How to build your custom GCC on CentOS


You can build any GCC version listed here.

Example: you want to build GCC 6.5.0

Step 1: download source code

wget https://bigsearcher.com/mirrors/gcc/releases/gcc-6.5.0/gcc-6.5.0.tar.gz

Result:

[root@tutorialspots ~]# wget https://bigsearcher.com/mirrors/gcc/releases/gcc-6.5.0/gcc-6.5.0.tar.gz
--2019-01-18 11:26:43--  https://bigsearcher.com/mirrors/gcc/releases/gcc-6.5.0/gcc-6.5.0.tar.gz
Resolving bigsearcher.com... 138.68.47.113
Connecting to bigsearcher.com|138.68.47.113|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 129189622 (123M) [application/x-gzip]
Saving to: `gcc-6.5.0.tar.gz'

100%[======================================>] 129,189,622 1.54M/s   in 66s

2019-01-18 11:27:49 (1.85 MB/s) - `gcc-6.5.0.tar.gz' saved [129189622/129189622]

Step 2: unpack the archive

tar xvf gcc-6.5.0.tar.gz

Step 3:

cd gcc-6.5.0

Step 4: install requirements

yum install -y libmpc-devel mpfr-devel gmp-devel 

Result:

[root@tutorialspots gcc-6.5.0]# yum install -y libmpc-devel mpfr-devel gmp-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrordenver.fdcservers.net
 * epel: mirror.compevo.com
 * extras: mirror.cogentco.com
 * rpmforge: mirror.lstn.net
 * updates: repo1.dal.innoscale.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package gmp-devel.x86_64 0:4.3.1-13.el6 will be installed
--> Processing Dependency: gmp = 4.3.1-13.el6 for package: gmp-devel-4.3.1-13.el6.x86_64
---> Package libmpc-devel.x86_64 0:0.8-3.el6 will be installed
--> Processing Dependency: libmpc = 0.8-3.el6 for package: libmpc-devel-0.8-3.el6.x86_64
--> Processing Dependency: libmpc.so.2()(64bit) for package: libmpc-devel-0.8-3.el6.x86_64
---> Package mpfr-devel.x86_64 0:2.4.1-6.el6 will be installed
--> Running transaction check
---> Package gmp.x86_64 0:4.3.1-7.el6_2.2 will be updated
---> Package gmp.x86_64 0:4.3.1-13.el6 will be an update
---> Package libmpc.x86_64 0:0.8-3.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package              Arch           Version                 Repository    Size
================================================================================
Installing:
 gmp-devel            x86_64         4.3.1-13.el6            base         171 k
 libmpc-devel         x86_64         0.8-3.el6               epel          21 k
 mpfr-devel           x86_64         2.4.1-6.el6             base          55 k
Installing for dependencies:
 libmpc               x86_64         0.8-3.el6               epel          44 k
Updating for dependencies:
 gmp                  x86_64         4.3.1-13.el6            base         207 k

Transaction Summary
================================================================================
Install       4 Package(s)
Upgrade       1 Package(s)

Total download size: 499 k
Downloading Packages:
(1/5): gmp-4.3.1-13.el6.x86_64.rpm                       | 207 kB     00:00
(2/5): gmp-devel-4.3.1-13.el6.x86_64.rpm                 | 171 kB     00:00
(3/5): libmpc-0.8-3.el6.x86_64.rpm                       |  44 kB     00:00
(4/5): libmpc-devel-0.8-3.el6.x86_64.rpm                 |  21 kB     00:00
(5/5): mpfr-devel-2.4.1-6.el6.x86_64.rpm                 |  55 kB     00:00
--------------------------------------------------------------------------------
Total                                           1.4 MB/s | 499 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : gmp-4.3.1-13.el6.x86_64                                      1/6
  Installing : gmp-devel-4.3.1-13.el6.x86_64                                2/6
  Installing : mpfr-devel-2.4.1-6.el6.x86_64                                3/6
  Installing : libmpc-0.8-3.el6.x86_64                                      4/6
  Installing : libmpc-devel-0.8-3.el6.x86_64                                5/6
  Cleanup    : gmp-4.3.1-7.el6_2.2.x86_64                                   6/6
  Verifying  : libmpc-0.8-3.el6.x86_64                                      1/6
  Verifying  : gmp-devel-4.3.1-13.el6.x86_64                                2/6
  Verifying  : mpfr-devel-2.4.1-6.el6.x86_64                                3/6
  Verifying  : libmpc-devel-0.8-3.el6.x86_64                                4/6
  Verifying  : gmp-4.3.1-13.el6.x86_64                                      5/6
  Verifying  : gmp-4.3.1-7.el6_2.2.x86_64                                   6/6

Installed:
  gmp-devel.x86_64 0:4.3.1-13.el6        libmpc-devel.x86_64 0:0.8-3.el6
  mpfr-devel.x86_64 0:2.4.1-6.el6

Dependency Installed:
  libmpc.x86_64 0:0.8-3.el6

Dependency Updated:
  gmp.x86_64 0:4.3.1-13.el6

Complete!

Step 4a: install zlib

yum install -y zlib-devel

Step 5:

./configure \
--prefix=$HOME/gcc \
--enable-languages=c,c++,fortran,objc,obj-c++ \
--enable-shared \
--without-included-gettext \
--enable-threads=posix \
--enable-nls \
--enable-clocale=gnu \
--enable-libstdcxx-time=yes \
--with-default-libstdcxx-abi=new \
--enable-libmpx \
--disable-multilib \
--with-system-zlib

Step 6:

make

This step takes so long 😀 be patient 😀

Step 7:

make install

Done! 😀 now we have gcc in $HOME/gcc/bin

[root@tutorialspots ~]# ls /root/gcc/bin
c++         gcov                     x86_64-pc-linux-gnu-gcc-6.5.0
cpp         gcov-dump                x86_64-pc-linux-gnu-gcc-ar
g++         gcov-tool                x86_64-pc-linux-gnu-gcc-nm
gcc         gfortran                 x86_64-pc-linux-gnu-gcc-ranlib
gcc-ar      x86_64-pc-linux-gnu-c++  x86_64-pc-linux-gnu-gfortran
gcc-nm      x86_64-pc-linux-gnu-g++
gcc-ranlib  x86_64-pc-linux-gnu-gcc

2 Comments

Leave a Reply