I recently upgraded my work machine to the latest Ubuntu version (natty narwhal, 11.<something>). By and large this went smoothly. However, we require gcc/g++-4.1 , and I had neglected to verify that this was available after the upgrade.
So, after a few abortive attempts to install packages I found on the web and such, I determined that what I really needed to do was just build gcc from source. I’ve done this a number of times in the past, so I knew what I was getting into, and by-and-large the process was very straightforward. I had to patch the gcc build files in a few places, though, so I figured I should document the process to save me and others time in the future.
NOTE: This is on an amd64 machine, building a compiler for the same platform. YMMV.
Install a few packages
For the build to work, you’ll need to install a few other packages that provide headers files, etc. The packages you’ll need are:
(There may be others, and I’ll try to update this list as I hear about them.)
Make MULTILIB look in the right directories
In gcc/config/i386/t-linux64 you need to correct the directories used for MULTILIB stuff. Change line 9 from:
MULTILIB_OSDIRNAMES = ../lib64 ../lib
MULTILIB_OSDIRNAMES = ../lib ../lib32
Change the “version” string that the build expects from ld
The gcc build parses the output of “ld –version”. Unfortunately, ubuntu decided to change that output, causing gcc to think that the ld version is really old. In libstdc++-v3/configure change line 8284 from:
sed -e 's/GNU ld version \([0-9.][0-9.]*\).*/\1/'`
sed -e 's/GNU ld (GNU Binutils for Ubuntu) \([0-9.][0-9.]*\).*/\1/'`
The full patch
You can download the patch from pastebin.
Be aware that this patch is only against gcc-core and gcc-g++, not against the entire gcc suite.
These steps should more-or-less do everything you need to download, patch, build, and install gcc/g++-4.1. Everything will get installed to /usr/local/gcc-4.1/[bin,lib], and the programs will have the suffix “-4.1″.
wget ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-4.1.2/gcc-core-4.1.2.tar.bz2 wget ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-4.1.2/gcc-g++-4.1.2.tar.bz2 tar jxvf gcc-core-4.1.2.tar.bz2 tar jxvf gcc-g++-4.1.2.tar.bz2 <download patch from pastebin> cd gcc-4.1.2 patch -p1 < ../FKkiciZz.txt ./configure --prefix=/usr/local/gcc-4.1 --program-suffix=-4.1 make make install ...set up symlinks to /usr/local/gcc-4.1/bin/g++-4.1, etc...