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.
wget http://ftpmirror.gnu.org/gcc/gcc-5.2.0/gcc-5.2.0.tar.bz2 tar xf gcc-5.2.0.tar.bz2 wget https://gmplib.org/download/gmp/gmp-6.0.0a.tar.xz tar xf gmp-6.0.0a.tar.xz mv gmp-6.0.0 gcc-5.2.0/gmp wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz tar xf mpc-1.0.3.tar.gz mv mpc-1.0.3 gcc-5.2.0/mpc wget http://www.mpfr.org/mpfr-current/mpfr-3.1.3.tar.xz 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 \ --disable-multilib \ --enable-languages=c,c++ \ --enable-libstdcxx-threads \ --enable-libstdcxx-time \ --enable-shared \ --enable-__cxa_atexit \ --disable-libunwind-exceptions \ --disable-libada \ --host x86_64-redhat-linux-gnu \ --build x86_64-redhat-linux-gnu \ --with-default-libstdcxx-abi=gcc4-compatible # 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-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 export LD_LIBRARY_PATH=$GCC5_ROOT/lib64:$GCC5_ROOT/lib:$LD_LIBRARY_PATH export LD_RUN_PATH=$GCC5_ROOT/lib64:$GCC5_ROOT/lib:$LD_RUN_PATH export LIBRARY_PATH=$GCC5_ROOT/lib64:$GCC5_ROOT/lib:$LIBRARY_PATH export INCLUDE_PATH=$GCC5_ROOT/include:$INCLUDE_PATH export CPLUS_INCLUDE_PATH=$GCC5_ROOT/include:$CPLUS_INCLUDE_PATH export C_INCLUDE_PATH=$GCC5_ROOT/include:$C_INCLUDE_PATH
Save the code block as a bash script (i.e.
env.sh), then call
source env.sh 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.