gcc/g++ 4.7.2
on Cygwin

LINKS:
* Matpack C++ Library
Pages


* Personal pages


* Achterbahn Stream Cipher Pages


* Install gcc/g++ 4.7.2 on Cygwin
 
How to Install gcc/g++ 4.7.2 on Cygwin


The recent Cygwin distribution (1.7.17-x) provides only an outdated Gnu compiler version. The latest version is gcc/g++ 4.5.3-3 from  the devel/gcc4-core package. If you need better C++11
standard complience you will have to install a newer gcc version right from the sources. This is easier than it may sound. The following report describes how gcc/g++ 4.7.2 can be installed on a Cygwin system.

Notice, that this is just a report on the steps I have performend during the installation process. I will not give any further support nor any guarantee that this will work in general. The installation works on a PC with an Intel Core i7 CPU 860 @ 2.8GHz (quad core), 8 GB RAM, and a 64 bit Windows 7 Home Premium OS, as well as on a HP 860 Laptop with an Intel Core i5 2450M @ 2.5GHz (dual core), 4GB RAM, and a 32 bit Windows 7 Enterprise OS.

*Cygwin Prerequisites
*Environment Variables
*Interference of Malware Scanners
*Obtain the Compiler Sources
*Build the Compiler
*Notes

Cygwin Prerequisites

The Cygwin installer and the packages can be obtained from http://cygwin.com/. The following Cygwin packages are needed for compilation and installation of the gcc/g++ compiler from the source:
  • bash
  • binutils
  • bzip2
  • cygwin
  • gcc4-core
  • gcc4-g++
  • gzip
  • m4
  • make
  • unzip
  • zip
To check that the packages are installed, you may run the command:

cygcheck -c bash binutils bzip2 cygwin gcc4-core\
  gcc4-g++ gzip m4 make unzip zip

A status value OK should be returned for each package.

Environment Variables

The build process requires that several environment variables are being set. If you are using the bash shell you can add the following lines to your .bashrc file:

export LD_LIBRARY_PATH=/usr/local/lib
export LIBRARY_PATH=/usr/local/lib
export CPATH=/usr/local/include

Users of tcsh shell have to use the appropriate syntax to set the variables. Additionally, the system PATH variable needs some extensions. Add the string

/usr/local/bin;/usr/bin;/bin;/usr/sbin;

before the entry /windows/system32. This is necessary, because otherwise Windows commands with the same names would be executed instead of the corresponding  Unix shell commands. You will easily find the dialog for setting environment variables in Windows 7 by right clicking the "Computer icon" on the desk top, choosing "Properties", selecting "Advanced system settings" in the left pane, selecting the "Advanced Tab", clicking on the "Environment Variables" button, choosing the lower pane with "System variables", and finally pressing the "Edit..." button. Now you can modify the PATH string. Reboot the computer before proceeding. You can check that the variables are set correctly by entering the shell commands

echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH};\
echo LIBRARY_PATH=${LIBRARY_PATH};\
echo CPATH=${CPATH};\
echo PATH=${PATH};

Interference of Malware Scanners

It might be necessary that you temporarily  deactivate your online malware scanner. My "Avast! Free Antivirus Version 7", for example, stopped several build scripts. Generally the online checker slows down the compilation process significantly.

Obtain the Compiler Sources

Download the following sources for the GNU gcc/g++ compiler and its prerequisites:
  1.   gmp-5.1.0.tar.bz2  from http://gmplib.org/
  2.   mpfr-3.1.1.tar.bz2 from http://mpfr.org/
  3.   mpc-1.0.1.tar.gz   from http://www.multiprecision.org/
  4.   gcc-4.7.2.tar.bz2  from a mirror at http://gcc.gnu.org/mirrors.html

Build the Compiler

Create a new build directory /usr/local/contrib and move all source packages into this directory. Then move into this directory by

cd /usr/local/contrib

The make tool has the ability to execute independent jobs in  parallel. On a multi-core machine this can significantly speed up the build process. The option

make -j N

generates upto N parallel threads. On a quad-core machine the value N = 4 is a good choice.

The building blocks of the compiler must be assembled exactly in the order given below. You should be patient. Especially the 4th step takes quite a long time. The whole build process can take 2 to 4 hours (of course depeding on the compute power of your machine).

1. Build GMP (Here: version 5.1.0)

tar -xf gmp-5.1.0.tar.bz2
cd gmp-5.1.0
./configure
make -j 4
make -j 4 check
make install
make clean          (OPTIONAL)
cd ..

2. Build MPFR (Here: version 3.1.1)

tar -xf mpfr-3.1.1.tar.bz2
cd mpfr-3.1.1
./configure
make -j 4
make -j 4 check
make install
make clean         (OPTIONAL)
cd ..

3. Build MPC (Here: version 1.0.1)

tar -xf mpc-1.0.1.tar.gz
cd mpc-1.0.1
./configure --enable-static --disable-shared
make -j 4
make -j 4 check
make install
make clean         (OPTIONAL)
cd ..

4. Build gcc (Here: version: 4.7.2)

tar -xf gcc-4.7.2.tar.bz2
mkdir gcc-build
cd gcc-build
../gcc-4.7.2/configure --enable-languages=c,c++
make -j 4
make install
make clean          (OPTIONAL)
cd ..

Currently, the self-check of the gcc is not working, so this step is omitted here.
Now you should check that the new compiler version 4.7.2 is called instead of the compiler used for the build process (here gcc-4.5.3). Enter the following commands:

gcc --version; g++ --version

The new compiler has been installed in /usr/local/bin. It is now the default compiler, because in the PATH variable /usr/local/bin  is before /usr/bin.

Notes

A very helpful article on the installation of a gcc 4.6 releases series compiler can be found at  http://cygwin.wikia.com/wiki/How_to_install_a_newer_version_of_GCC.



 Copyright (C) 1991-2013 by Berndt M. Gammel
  mail to: reply [AT-symbol] matpack.de
*Matpack C++ Library      Impressum Last change: 5.1.2013