Date

Sometimes you need an older version of GCC. Not often, but sometimes. For instance, since GCC switched to the gnu14 dialect in GCC6 it might be the easier option for a large project which isn't fully tested with C++11 syntax. Usually it would be easier to specify -std=c++98 (for example, as the argument to CMAKE_CXX_FLAGS) but with the large Slicer project I found that the flag didn't propagate down into subdirectories like it should.

On top of that, there were some other subprojects which weren't ready for 6.1.1, and after monkey-patching two of them (I don't want to name any names) I decided to just go with an older compiler.

So, 4.6.3. This is the last version I remember shipping with Ubuntu 12.04. It should work.

First thing you need to do is download it into whatever directory you're doing to use.

mkdir ~/gcc && cd ~/gcc
wget https://ftp.gnu.org/gnu/gcc/gcc-4.6.3/gcc-4.6.3.tar.gz
tar xzf gcc-4.6.3.tar.gz

Go ahead and make a build and an install directory:

mkdir gcc-build-4.6.3
mkdir gcc-install-4.6.3

First we're going to go into the source directory and download the prerequisites. If you have GMP, MPFR and MPC support libraries already installed you can skip this, but sometimes it's safest to minimize how much we deviate from the supported packages. My system's package compatibility is why we're doing this in the first place, after all.

cd gcc-4.6.2
./contrib/download_prerequisites

Now we will start the configuratin'. We want to specify options for

  • install directory
  • supported languages
  • multilib (32-bit library) support
cd ../gcc-build-4.6.3
../gcc-4.6.2/configure --prefix=/home/chris/gcc/gcc-install-4.6.3 --without-multilib --enable-languages=c,c++

Normally you could stop here and begin building. But, evidently gcc wants to build its documentation too, and to do so it relies on an old version of Texinfo. New versions will throw errors about stricter requirements on the item and itemx tags. You can try to disable building documentation altogether by adding the --without-docdir flag to the configure command, but some report that this will only stop it from installing, not from (erroring out during) building.

The solution from the osdev wiki is to simply overwrite the MAKEINFO variable in the Makefile to something that doesn't exist, with the following command:

echo "MAKEINFO = :" >> Makefile

Now we can get on with compiling.

make
make install

You may get the following error reported here:

In file included from /home/ionic/gcc46/src/gcc-4.6.3/libgcc/../gcc/unwind-dw2.c:333:0:
/home/ionic/gcc46/src/gcc-4.6.3/libgcc/../gcc/config/i386/linux-unwind.h: In function ‘x86_fallback_frame_state’:
/home/ionic/gcc46/src/gcc-4.6.3/libgcc/../gcc/config/i386/linux-unwind.h:138:17: error: field ‘info’ has incomplete type
make[3]: *** [unwind-dw2.o] Errore 1
make[3]: Leaving directory `/home/ionic/gcc46/src/gcc-build/i686-pc-linux-gnu/libgcc'
make[2]: *** [all-stage1-target-libgcc] Errore 2
make[2]: Leaving directory `/home/ionic/gcc46/src/gcc-build'
make[1]: *** [stage1-bubble] Errore 2
make[1]: Leaving directory `/home/ionic/gcc46/src/gcc-build'
make: *** [all] Errore 2

In this case, apply the following patch (found here):

--- a/gcc/config/i386/linux-unwind.h    2011-01-03 20:52:22.000000000 +0000
+++ b/gcc/config/i386/linux-unwind.h    2012-07-06 12:23:51.562859470 +0100
@@ -133,9 +133,9 @@
     {
       struct rt_sigframe {
    int sig;
-   struct siginfo *pinfo;
+   siginfo_t *pinfo;
    void *puc;
-   struct siginfo info;
+   siginfo_t info;
    struct ucontext uc;
       } *rt_ = context->cfa;
       /* The void * cast is necessary to avoid an aliasing warning.

using the command

patch -Np1 -i ../siginfo_t_fix.patch

in your source directory.

Hopefully this works for you. If there was a better way for me to do this, please let me know in the comments... HA there are no comments. But please let me know by email and I'll amend the post.