Build GCC 5.2 on RHEL 6

To build GCC, we need other three components, GMP, MPC, and MPFR. And I found a lazy way to compile all of them together here. But because GMP, MPC, MPFR are compiled together with GCC, they're certainly not installed before the new GCC is installed. So we can't do make -k check to make a test after the compilation in this way. If you'd like to do a test, please go the traditional way, build and install them one by one seperately.

tar xf gcc-5.2.0.tar.bz2
tar xf gmp-6.0.0a.tar.xz
mv gmp-6.0.0 gcc-5.2.0/gmp
tar xf mpc-1.0.3.tar.gz
mv mpc-1.0.3 gcc-5.2.0/mpc
tar xf mpfr-3.1.3.tar.xz
mv mpfr-3.1.3 gcc-5.2.0/mpfr
mkdir gcc-5.2.0/gcc-build && cd gcc-5.2.0/gcc-build
# I don't have root privilege, so install to a subdir in my home directory
../configure --prefix=$HOME/gcc5 </span>
--disable-multilib </span>
--enable-languages=c,c++ </span>
--enable-libstdcxx-threads </span>
--enable-libstdcxx-time </span>
--enable-shared </span>
--enable-__cxa_atexit </span>
--disable-libunwind-exceptions </span>
--disable-libada </span>
--host x86_64-redhat-linux-gnu </span>
--build x86_64-redhat-linux-gnu </span>
# For clusters, you should request a compute node in slurm to do the compilation. Don't do these in head node
make -j4
make install

With --with-default-libstdcxx-abi=gcc4-compatible, we avoid recompiling all C++ libraries built using older GCC (prior to GCC 5.1). This ensures the default ABI is the old, GCC4-compatble one instead of the newly introduced CXX11 ABI. Check Configure - The GNU C++ Library for details.

To use this GCC, we need to change environment variables as follows:

export GCC5_ROOT=$HOME/gcc5
export PATH=$GCC5_ROOT/bin:$PATH
export MANPATH=$GCC5_ROOT/share/man:MANPATH
export INFOPATH=$GCC5_ROOT/share/info:$INFOPATH

Save the code block as a bash script (i.e., then call source whenever you want to use GCC 5.2.0 or need to run a program built using GCC 5.2.0.

And again, because we default to old ABI, older objects produced by prior compilers are compatible (as long as you don't override the default and use the new ABI). To use new ABI as default, one might need to do a mass rebuild as Fedora 22 didn't do but Fedora 23 would do.