New GCC on an old Linux distribution
Sometimes you need to have a new version of
gcc (i.e. to be able to leverage the features from
C++11 standard), but you have an old distribution which doesn't have new
gcc inside its repository. Here's how you can compile your own
gcc on that distribution.
Acquire gcc tarball
First you need to download the main
gcc tarball from the official
$ wget ftp://gd.tuwien.ac.at/gnu/gcc/releases/gcc-4.9.0/gcc-4.9.0.tar.bz2
After downloading, unpack the archive to some directory. Make sure you'll have enough space to compile the whole package though. I don't remember exactly how much space it will take, but it's safe to assume that it will take a lot.
If you're installing it on a virtual machine (I did), maybe it's a good idea to use some kind of networked file system solution, like
NFS, or at last
sshfs should also work). This way you would host all of the temporary object files on you host machine, which probably has lots of gigabytes of free space, ready to be used (right?).
$ tar xfj gcc-*.tar.bz2
This will unpack the package to the current directory. For the purposes of this post, I'll assume this directory will be named
Next, you'll need some thirdparty libraries required by
GMP (GNU Multiple Precision Library) - website. Unpack it with:
$ tar xfj gmp-*.tar.bz2
Then create symbolic link of newly created directory to the
gmp directory, like this:
$ ln -sf gmp-6.0.0 gmp
It should result in having the directory placed in
This way the build system of
gcc should handle building this library together with
MPFR (Multiple-Precision Floating-point computations with correct Rounding) - website. Unpack it, and create a symbolic link of its directory to the
MPC (expansion over
MPFR if I understand it correctly) - website. Unpack it, and create a symbolic link of its directory to the
ISL (Integer Set Library) - website. Unpack it, and create a symbolic link of its directory to the
If you're getting some compilation errors related to
isl_int, use an older version of the library, before
0.13 version removes the
isl_int symbol, so this major update could be too major for other libraries (like CLooG). The version that worked for me is
If you do need to change the version of the
ISL library, make sure you'll clean the current configuration cache, created after running
configure script. Best way is to remove the whole source directory and recreate it from scratch. Oh, maybe
make distclean will help too.
CLooG (Chunky LOOp Generator) - website. Unpack it, and create a symbolic link of its directory to the
Of course, you will also need standard combo in the form of
autotools, older version of the compiler, but that's pretty obvious, so I'll just skip it.
After installing the dependencies, next step is pretty straightforward:
$ ./configure --disable-multilib --prefix=/usr/local/gcc49 --enable-threads --enable-languages=c,c++
It is probably OK to get some errors, as long they're not stopping the build process. Please note that this process will take a long time, so you'll have to plan it ahead.
If you're trying to compile it through an
ssh connection, I suggest you use a terminal detaching tool like
tmux, so you'll be able to close the connection without interrupting the build.
To finish the process, don't forget to
make install. Your new gcc will be installed to
Please note that you may need to use
-static-libgcc options when linking your executable file! See the proper documentation of
gcc to read more about characteristics of these options.