I sometimes see even seasoned developers be reluctant to use a different gcc version (ie. to reproduce a potentially compiler-specific issue or just to experiment with new optimisations or features). The reason is a fear of breaking their system by installing multiple compilers, or even by replacing their system compiler with a new one.
But actually it is very easy to install multiple gcc versions without any risk of “polluting” the development environment. At least on Debian or Debian-based distributions (I am using Ubuntu) which can automatically install dependencies.
sudo apt-get build-dep gcc-4.1 g++-4.1
That is a brilliant feature of Debian apt, a life-saver when compiling sources with complex dependencies.
Here is how it goes:
cd /usr/local/src/ wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-4.3.1/gcc-core-4.3.1.tar.bz2 wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-4.3.1/gcc-g++-4.3.1.tar.bz2 mkdir gcc-4.3.1 cd gcc-4.3.1/ bzip2 -dc ../gcc-core-4.3.1.tar.bz2 | tar xf - bzip2 -dc ../gcc-g++-4.3.1.tar.bz2 | tar xf - mkdir build cd build ../gcc-4.3.1/configure --prefix=/usr/local/src/gcc-4.3.1 --disable-multilib time make -j4 make install
These days it doesn’t even take long to build, just under 15 minutes on a 2.4GHz Q6600 (cheap quad-core Intel).
Now, the new GCC is installed in a completely seperate location, so it does not interfere in any way with normal work. But to use it to build some particular software, just do something like this:
PATH="/usr/local/src/gcc-4.3.1/bin:$PATH" ./configure PATH="/usr/local/src/gcc-4.3.1/bin:$PATH" make
Well, there is one snag, that is why I have the –disable-multilib in the above ./configure. Otherwise I get this:
In file included from /usr/local/src/gcc-4.3.1/build/./gcc/include-fixed/features.h:355, from /usr/include/stdio.h:28, from ../../../../gcc-4.3.1/libgcc/../gcc/tsystem.h:90, from ../../../../gcc-4.3.1/libgcc/../gcc/libgcc2.c:33: /usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
This is some problem with Ubuntu Feisty which puts that include file in /usr/include/i486-linux-gnu/gnu/stubs-32.h where apparently GCC does not look for it. I do not need to build any 32-bit binaries, so –disable-multilib is a quick solution.
Hopefully this is fixed somehow in Hardy.