GCC 4.9.2: install via RPMs or from source

Install a newer version of gcc, the developers ask. Should be easy, right? Not as easy as you might have hoped.

RHEL 6 and 7 include a package set of RPMs called devtoolset, which will help you install gcc-4.9.2 and its dependencies.

Installing the RPMs:

If you have the old (classic) RHN registration, then install these tools to migrate away from classic.

RHEL 6:

yum install subscription-manager-migration subscription-manager-migration-data

If the system is still registered to classic:
rhn-migrate-classic-to-rhsm

If registering on subscription management for the first time:
subscription-manager register –username username –password XXXXX

Enable these repos:

subscription-manager repos –enable rhel-6-server-optional-rpms

subscription-manager repos –enable rhel-server-rhscl-6-rpms

yum install devtoolset-3

# or specific versions like these:

yum install devtoolset-3-gcc-4.9.2-6.2.el6.x86_64 devtoolset-3-gcc-c++-4.9.2-6.2.el6.x86_64

 

Then create a symlink (or let your config management tool like puppet do this for you) from /opt/rh/devtoolset-3/root/usr/bin/gcc to /usr/local/bin/gcc and /usr/local/bin/g++.

 

RHEL 7:

subscription-manager register –username username –password XXXXX

Enable repos:

subscription-manager repos –enable rhel-server-rhscl-7-rpms

subscription-manager repos –enable rhel-7-server-optional-rpms

 

yum install devtoolset-3-gcc.x86_64 devtoolset-3-gcc-c++.x86_64

Create symlinks to /usr/local/bin/gcc and ../g++.

Compiling from source:

On RHEL 5, there is no devtoolset package available (as far as I’ve found), so you can build gcc-4.9.2 from source. Here are the options I used.

Download gcc tar file from your closest mirror, for example:

wget http://mirrors-usa.go-parts.com/gcc/releases/gcc-4.9.2/gcc-4.9.2.tar.gz

Untar and cd into the new contrib folder

Download dependencies by running script:

sh ./download_prerequisites

This goes out to the mirrors and downloads gmp, mpfr, and mpc into the contrib folder.

Set environment variables:

export LD_LIBRARY_PATH=/usr/local/lib
export CXXFLAGS=-fPIC

Install each one by cd’ing into their individual directory, configure, make, and make install. (These were supposed to be built automatically, but that didn’t seem to work.)

cd gcc-4.9.2/contrib/gmp

./configure —enable-shared
make && make check
make install

cd ../contrib/mpfr
./configure –with-gmp-lib=/usr/local/lib
make && make check
make install

cd ../contrib/mpc
./configure –with-gmp-lib=/usr/local/lib –with-mpfr-lib=/usr/local/lib
make && make install

 

Then cd back to the gcc-4.9.2 folder and run the main configure command. Docs discourage building in the main gcc-4.9.2 folder, so create a new subfolder to build it in.

mkdir objdir
cd objdir
../configure –prefix=/usr/local/gcc492 –with-gmp-lib=/usr/local/lib –with-mpfr-lib=/usr/local/lib –with-mpc-lib=/usr/local/lib
make
make install

 

Confirm by checking the version of gcc now installed:
/usr/local/gcc492/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/usr/local/gcc492/bin/gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc492/libexec/gcc/x86_64-unknown-linux-gnu/4.9.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure –prefix=/usr/local/gcc492 –with-gmp-lib=/usr/local/lib –with-mpfr-lib=/usr/local/lib –with-mpc-lib=/usr/local/lib
Thread model: posix
gcc version 4.9.2 (GCC)

Advertisements