How to install gcc in Cygwin


Read more:
How to install cygwin
How to add packages after install Cygwin

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
  • gcc-core
  • gcc-g++
  • gzip
  • m4
  • make
  • unzip
  • zip

To check that the packages are installed, you may run the command:

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

Result:

$ cygcheck -c bash binutils bzip2 cygwin gcc-core gcc-g++ gzip m4 make unzip zip
Cygwin Package Information
Package              Version        Status
bash                 4.3.42-4       OK
bzip2                1.0.6-2        OK
cygwin               2.5.1-1        OK
gzip                 1.7-2          OK
m4                   1.4.17-2       OK
make                 4.1-1          OK
unzip                6.0-15         OK
zip                  3.0-12         OK

Must install binutils, gcc-core and gcc-g++

Installation binutils:

$ apt-cyg install binutils
Installing binutils
--2016-08-20 22:27:02--  http://cygwin.mirror.constant.com//x86_64/release/binutils/binutils-2.25-4.tar.xz
Resolving cygwin.mirror.constant.com (cygwin.mirror.constant.com)... 108.61.5.83
Connecting to cygwin.mirror.constant.com (cygwin.mirror.constant.com)|108.61.5.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5233952 (5,0M) [application/octet-stream]
Saving to: ‘binutils-2.25-4.tar.xz’

binutils-2.25-4.tar 100%[===================>]   4,99M   136KB/s    in 77s

2016-08-20 22:28:25 (66,6 KB/s) - ‘binutils-2.25-4.tar.xz’ saved [5233952/5233952]

binutils-2.25-4.tar.xz: OK
Unpacking...
Package binutils requires the following packages, installing:
cygwin libintl8 zlib0
Package cygwin is already installed, skipping
Package libintl8 is already installed, skipping
Package zlib0 is already installed, skipping
Package binutils installed

Installation gcc-core:

$ apt-cyg install gcc-core
Installing gcc-core
--2016-08-20 22:42:40--  http://cygwin.mirror.constant.com//x86_64/release/gcc/gcc-core/gcc-core-5.3.0-5.tar.xz
Resolving cygwin.mirror.constant.com (cygwin.mirror.constant.com)... 108.61.5.83
Connecting to cygwin.mirror.constant.com (cygwin.mirror.constant.com)|108.61.5.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16841096 (16M) [application/octet-stream]
Saving to: ‘gcc-core-5.3.0-5.tar.xz’

gcc-core-5.3.0-5.ta 100%[===================>]  16,06M   403KB/s    in 70s

2016-08-20 22:43:51 (235 KB/s) - ‘gcc-core-5.3.0-5.tar.xz’ saved [16841096/16841096]

gcc-core-5.3.0-5.tar.xz: OK
Unpacking...
Package gcc-core requires the following packages, installing:
bash binutils cygwin cygwin-devel libatomic1 libgcc1 libgmp10 libgomp1 libiconv2 libintl8 libisl13 libmpc3 libmpfr4 libquadmath0 libssp0 libvtv0 w32api-headers w32api-runtime windows-default-manifest zlib0
Package bash is already installed, skipping
Package binutils is already installed, skipping
Package cygwin is already installed, skipping
Installing cygwin-devel
--2016-08-20 22:44:09--  http://cygwin.mirror.constant.com//x86_64/release/cygwin/cygwin-devel/cygwin-devel-2.5.1-1.tar.xz
Resolving cygwin.mirror.constant.com (cygwin.mirror.constant.com)... 108.61.5.83
Connecting to cygwin.mirror.constant.com (cygwin.mirror.constant.com)|108.61.5.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 282796 (276K) [application/octet-stream]
Saving to: ‘cygwin-devel-2.5.1-1.tar.xz’

cygwin-devel-2.5.1- 100%[===================>] 276,17K  92,7KB/s    in 3,0s

2016-08-20 22:44:13 (92,7 KB/s) - ‘cygwin-devel-2.5.1-1.tar.xz’ saved [282796/282796]

cygwin-devel-2.5.1-1.tar.xz: OK
Unpacking...
Installing libatomic1
--2016-08-20 22:44:20--  http://cygwin.mirror.constant.com//x86_64/release/gcc/libatomic1/libatomic1-5.3.0-5.tar.xz
Resolving cygwin.mirror.constant.com (cygwin.mirror.constant.com)... 108.61.5.83
Connecting to cygwin.mirror.constant.com (cygwin.mirror.constant.com)|108.61.5.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6356 (6,2K) [application/octet-stream]
Saving to: ‘libatomic1-5.3.0-5.tar.xz’

libatomic1-5.3.0-5. 100%[===================>]   6,21K  --.-KB/s    in 0,002s

2016-08-20 22:44:21 (2,83 MB/s) - ‘libatomic1-5.3.0-5.tar.xz’ saved [6356/6356]

libatomic1-5.3.0-5.tar.xz: OK
Unpacking...
Package libatomic1 requires the following packages, installing:
cygwin
Package cygwin is already installed, skipping
Package libgcc1 is already installed, skipping
Package libgmp10 is already installed, skipping
Installing libgomp1
--2016-08-20 22:44:29--  http://cygwin.mirror.constant.com//x86_64/release/gcc/libgomp1/libgomp1-5.3.0-5.tar.xz
Resolving cygwin.mirror.constant.com (cygwin.mirror.constant.com)... 108.61.5.83
Connecting to cygwin.mirror.constant.com (cygwin.mirror.constant.com)|108.61.5.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 42408 (41K) [application/octet-stream]
Saving to: ‘libgomp1-5.3.0-5.tar.xz’

libgomp1-5.3.0-5.ta 100%[===================>]  41,41K  65,0KB/s    in 0,6s

2016-08-20 22:44:31 (65,0 KB/s) - ‘libgomp1-5.3.0-5.tar.xz’ saved [42408/42408]

libgomp1-5.3.0-5.tar.xz: OK
Unpacking...
Package libgomp1 requires the following packages, installing:
cygwin libgcc1
Package cygwin is already installed, skipping
Package libgcc1 is already installed, skipping
Package libiconv2 is already installed, skipping
Package libintl8 is already installed, skipping
Installing libisl13
--2016-08-20 22:44:40--  http://cygwin.mirror.constant.com//x86_64/release/isl/libisl13/libisl13-0.14.1-1.tar.xz
Resolving cygwin.mirror.constant.com (cygwin.mirror.constant.com)... 108.61.5.83
Connecting to cygwin.mirror.constant.com (cygwin.mirror.constant.com)|108.61.5.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 375052 (366K) [application/octet-stream]
Saving to: ‘libisl13-0.14.1-1.tar.xz’

libisl13-0.14.1-1.t 100%[===================>] 366,26K  48,7KB/s    in 7,5s

2016-08-20 22:44:48 (48,7 KB/s) - ‘libisl13-0.14.1-1.tar.xz’ saved [375052/375052]

libisl13-0.14.1-1.tar.xz: OK
Unpacking...
Package libisl13 requires the following packages, installing:
cygwin libgmp10
Package cygwin is already installed, skipping
Package libgmp10 is already installed, skipping
Installing libmpc3
--2016-08-20 22:44:57--  http://cygwin.mirror.constant.com//x86_64/release/mpclib/libmpc3/libmpc3-1.0.3-1.tar.xz
Resolving cygwin.mirror.constant.com (cygwin.mirror.constant.com)... 108.61.5.83
Connecting to cygwin.mirror.constant.com (cygwin.mirror.constant.com)|108.61.5.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 34044 (33K) [application/octet-stream]
Saving to: ‘libmpc3-1.0.3-1.tar.xz’

libmpc3-1.0.3-1.tar 100%[===================>]  33,25K  54,8KB/s    in 0,6s

2016-08-20 22:44:58 (54,8 KB/s) - ‘libmpc3-1.0.3-1.tar.xz’ saved [34044/34044]

libmpc3-1.0.3-1.tar.xz: OK
Unpacking...
Package libmpc3 requires the following packages, installing:
cygwin libgmp10 libmpfr4
Package cygwin is already installed, skipping
Package libgmp10 is already installed, skipping
Package libmpfr4 is already installed, skipping
Package libmpfr4 is already installed, skipping
Installing libquadmath0
--2016-08-20 22:45:05--  http://cygwin.mirror.constant.com//x86_64/release/gcc/libquadmath0/libquadmath0-5.3.0-5.tar.xz
Resolving cygwin.mirror.constant.com (cygwin.mirror.constant.com)... 108.61.5.83
Connecting to cygwin.mirror.constant.com (cygwin.mirror.constant.com)|108.61.5.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 130632 (128K) [application/octet-stream]
Saving to: ‘libquadmath0-5.3.0-5.tar.xz’

libquadmath0-5.3.0- 100%[===================>] 127,57K  58,7KB/s    in 2,2s

2016-08-20 22:45:08 (58,7 KB/s) - ‘libquadmath0-5.3.0-5.tar.xz’ saved [130632/130632]

libquadmath0-5.3.0-5.tar.xz: OK
Unpacking...
Package libquadmath0 requires the following packages, installing:
cygwin libgcc1
Package cygwin is already installed, skipping
Package libgcc1 is already installed, skipping
Package libssp0 is already installed, skipping
Installing libvtv0
--2016-08-20 22:45:16--  http://cygwin.mirror.constant.com//x86_64/release/gcc/libvtv0/libvtv0-5.3.0-5.tar.xz
Resolving cygwin.mirror.constant.com (cygwin.mirror.constant.com)... 108.61.5.83
Connecting to cygwin.mirror.constant.com (cygwin.mirror.constant.com)|108.61.5.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1928 (1,9K) [application/octet-stream]
Saving to: ‘libvtv0-5.3.0-5.tar.xz’

libvtv0-5.3.0-5.tar 100%[===================>]   1,88K  --.-KB/s    in 0s

2016-08-20 22:45:18 (6,21 MB/s) - ‘libvtv0-5.3.0-5.tar.xz’ saved [1928/1928]

libvtv0-5.3.0-5.tar.xz: OK
Unpacking...
Package libvtv0 requires the following packages, installing:
cygwin
Package cygwin is already installed, skipping
Installing w32api-headers
--2016-08-20 22:45:26--  http://cygwin.mirror.constant.com//x86_64/release/w32api-headers/w32api-headers-4.0.4-1.tar.xz
Resolving cygwin.mirror.constant.com (cygwin.mirror.constant.com)... 108.61.5.83
Connecting to cygwin.mirror.constant.com (cygwin.mirror.constant.com)|108.61.5.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4522336 (4,3M) [application/octet-stream]
Saving to: ‘w32api-headers-4.0.4-1.tar.xz’

w32api-headers-4.0. 100%[===================>]   4,31M   474KB/s    in 18s

2016-08-20 22:45:46 (241 KB/s) - ‘w32api-headers-4.0.4-1.tar.xz’ saved [4522336/4522336]

w32api-headers-4.0.4-1.tar.xz: OK
Unpacking...
Installing w32api-runtime
--2016-08-20 22:46:02--  http://cygwin.mirror.constant.com//x86_64/release/w32api-runtime/w32api-runtime-4.0.4-1.tar.xz
Resolving cygwin.mirror.constant.com (cygwin.mirror.constant.com)... 108.61.5.83
Connecting to cygwin.mirror.constant.com (cygwin.mirror.constant.com)|108.61.5.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1948268 (1,9M) [application/octet-stream]
Saving to: ‘w32api-runtime-4.0.4-1.tar.xz’

w32api-runtime-4.0. 100%[===================>]   1,86M   115KB/s    in 13s

2016-08-20 22:46:16 (147 KB/s) - ‘w32api-runtime-4.0.4-1.tar.xz’ saved [1948268/1948268]

w32api-runtime-4.0.4-1.tar.xz: OK
Unpacking...
Package w32api-runtime requires the following packages, installing:
w32api-headers
Package w32api-headers is already installed, skipping
Installing windows-default-manifest
--2016-08-20 22:46:40--  http://cygwin.mirror.constant.com//x86_64/release/windows-default-manifest/windows-default-manifest-6.4-1.tar.xz
Resolving cygwin.mirror.constant.com (cygwin.mirror.constant.com)... 108.61.5.83
Connecting to cygwin.mirror.constant.com (cygwin.mirror.constant.com)|108.61.5.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1244 (1,2K) [application/octet-stream]
Saving to: ‘windows-default-manifest-6.4-1.tar.xz’

windows-default-man 100%[===================>]   1,21K  --.-KB/s    in 0s

2016-08-20 22:46:41 (19,4 MB/s) - ‘windows-default-manifest-6.4-1.tar.xz’ saved [1244/1244]

windows-default-manifest-6.4-1.tar.xz: OK
Unpacking...
Package zlib0 is already installed, skipping
Package gcc-core installed

Installation gcc-g++:

$ apt-cyg install gcc-g++
Installing gcc-g++
--2016-08-20 22:47:46--  http://cygwin.mirror.constant.com//x86_64/release/gcc/gcc-g++/gcc-g++-5.3.0-5.tar.xz
Resolving cygwin.mirror.constant.com (cygwin.mirror.constant.com)... 108.61.5.83
Connecting to cygwin.mirror.constant.com (cygwin.mirror.constant.com)|108.61.5.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10025164 (9,6M) [application/octet-stream]
Saving to: ‘gcc-g++-5.3.0-5.tar.xz’

gcc-g++-5.3.0-5.tar 100%[===================>]   9,56M   471KB/s    in 30s

2016-08-20 22:48:17 (328 KB/s) - ‘gcc-g++-5.3.0-5.tar.xz’ saved [10025164/10025164]

gcc-g++-5.3.0-5.tar.xz: OK
Unpacking...
Package gcc-g++ requires the following packages, installing:
cygwin gcc-core libgmp10 libiconv2 libintl8 libisl13 libmpc3 libmpfr4 libstdc++6 zlib0
Package cygwin is already installed, skipping
Package gcc-core is already installed, skipping
Package libgmp10 is already installed, skipping
Package libiconv2 is already installed, skipping
Package libintl8 is already installed, skipping
Package libisl13 is already installed, skipping
Package libmpc3 is already installed, skipping
Package libmpfr4 is already installed, skipping
Package libstdc++6 is already installed, skipping
Package zlib0 is already installed, skipping
Package gcc-g++ installed

cygwin install gcc

Environment variables:

add to the file /home/Administrator/.bashrc some lines below:

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

Close Cygwin terminal and reopen it.

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};

Result:

LD_LIBRARY_PATH=/usr/local/lib
LIBRARY_PATH=/usr/local/lib
CPATH=/usr/local/include
PATH=/usr/local/bin:/usr/bin:/cygdrive/c/ProgramData/Oracle/Java/javapath:/cygdrive/c/Program Files (x86)/Common Files/Intel/Shared Files/cpp/bin/Intel64:/cygdrive/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files (x86)/Bitvise SSH Client:/cygdrive/c/Program Files/Microsoft Windows Performance Toolkit:/cygdrive/c/Program Files/Microsoft SQL Server/110/Tools/Binn:/cygdrive/c/Program Files (x86)/Windows Kits/8.0/Windows Performance Toolkit:/cygdrive/c/Program Files (x86)/Skype/Phone:/cygdrive/c/Program Files/nodejs:/cygdrive/c/Program Files/Java/jdk1.8.0_66/bin:/cygdrive/c/Program Files (x86)/QuickTime/QTSystem:/cygdrive/d/HaxeToolkit/haxe:/cygdrive/d/HaxeToolkit/neko:/cygdrive/c/ProgramData/ComposerSetup/bin:/cygdrive/d/AppServ/Apache2.2/bin:/cygdrive/d/AppServ/php5:/cygdrive/d/AppServ/MySQL/bin:/cygdrive/c/Python27:/cygdrive/c/GTK/bin:/cygdrive/c/Users/Administrator/AppData/Roaming/npm:/cygdrive/c/Eclipse:/cygdrive/c/Users/Administrator/AppData/Roaming/Composer/vendor/bin

Prepare the Compiler Sources

Create folder /usr/local/contrib

mkdir /usr/local/contrib

Then move into this directory by

cd /usr/local/contrib

Then download theses sources

1. gmp-6.1.1.tar.bz2 from http://gmplib.org/
2. mpfr-3.1.4.tar.bz2 from http://mpfr.org/
3. mpc-1.0.3.tar.gz from http://www.multiprecision.org/
4. gcc-6.1.0.tar.bz2 from a mirror at http://gcc.gnu.org/mirrors.html

and put them in this folder.

$ wget https://gmplib.org/download/gmp/gmp-6.1.1.tar.bz2
--2016-08-20 23:20:31--  https://gmplib.org/download/gmp/gmp-6.1.1.tar.bz2
Resolving gmplib.org (gmplib.org)... 37.252.122.230
Connecting to gmplib.org (gmplib.org)|37.252.122.230|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2384919 (2,3M) [application/octet-stream]
Saving to: ‘gmp-6.1.1.tar.bz2’

gmp-6.1.1.tar.bz2   100%[===================>]   2,27M  16,9KB/s    in 1m 59s

2016-08-20 23:22:33 (19,5 KB/s) - ‘gmp-6.1.1.tar.bz2’ saved [2384919/2384919]

$ wget http://www.mpfr.org/mpfr-current/mpfr-3.1.4.tar.bz2
--2016-08-20 23:44:44--  http://www.mpfr.org/mpfr-current/mpfr-3.1.4.tar.bz2
Resolving www.mpfr.org (www.mpfr.org)... 152.81.144.6
Connecting to www.mpfr.org (www.mpfr.org)|152.81.144.6|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1279284 (1,2M) [application/x-bzip2]
Saving to: ‘mpfr-3.1.4.tar.bz2’

mpfr-3.1.4.tar.bz2  100%[===================>]   1,22M   216KB/s    in 8,3s

2016-08-20 23:44:54 (150 KB/s) - ‘mpfr-3.1.4.tar.bz2’ saved [1279284/1279284]

$ wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
--2016-08-20 23:47:09--  ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
           => ‘mpc-1.0.3.tar.gz’
Resolving ftp.gnu.org (ftp.gnu.org)... 208.118.235.20, 2001:4830:134:3::b
Connecting to ftp.gnu.org (ftp.gnu.org)|208.118.235.20|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /gnu/mpc ... done.
==> SIZE mpc-1.0.3.tar.gz ... 669925
==> PASV ... done.    ==> RETR mpc-1.0.3.tar.gz ... done.
Length: 669925 (654K) (unauthoritative)

mpc-1.0.3.tar.gz    100%[===================>] 654,22K   404KB/s    in 1,6s

2016-08-20 23:47:14 (404 KB/s) - ‘mpc-1.0.3.tar.gz’ saved [669925]
$ wget http://gcc.parentingamerica.com/releases/gcc-6.1.0/gcc-6.1.0.tar.bz2
--2016-08-20 23:47:18--  http://gcc.parentingamerica.com/releases/gcc-6.1.0/gcc-6.1.0.tar.bz2
Resolving gcc.parentingamerica.com (gcc.parentingamerica.com)... 70.38.15.129
Connecting to gcc.parentingamerica.com (gcc.parentingamerica.com)|70.38.15.129|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 99267556 (95M) [application/x-bzip2]
Saving to: ‘gcc-6.1.0.tar.bz2’

gcc-6.1.0.tar.bz2   100%[===================>]  94,67M   734KB/s    in 2m 31s

2016-08-20 23:49:49 (643 KB/s) - ‘gcc-6.1.0.tar.bz2’ saved [99267556/99267556]

Pre-Build Notes

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.

Install GMP

How to Install GMP in Cygwin

Install MPFR (Here: version 3.1.4)

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

Install MPC (Here: version 1.0.3)

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

Install gcc (Here: version: 6.1.0)

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

Related Post

Trackbacks/Pingbacks

  1. How to Install GMP in Cygwin | Free Online Tutorials - August 20, 2016

    […] Read first: How to install gcc in Cygwin […]

Leave a Reply