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.
# I don't have root privilege, so install to a subdir in my home directory
../configure --prefix=$HOME/gcc5 </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
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:
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.