Leo's Blog

Home

[Wed Apr 11 09:46:42 2012] Installing GCC from source

[Wed Apr 11 09:46:42 2012] Installing GCC from source

I needed to install GCC v4.7 to be able to play with OpenMP v3.1 and with MIT/Intel Cilk Plus. Although there is a nice GCC installation page here, I was lacking a step by step tutorial on how to install it. Here's my crack at it, for my future reference. Maybe it can be of help to someone else.

objdir should not be the same as srcdir, so

At this point, configure told me that there was a problem with some dependencies: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+. So after a few sudo apt-cache searches:

After that ../gcc-4.7.0/configure --prefix=/opt/ --program-suffix=-4.7 worked just fine. Notice that at this step, your milage may vary, since you may have to install several other packages (see here for the prerequisites to build.)

To build in parallel (and take far less time), use the -j flag and pass it the number of physical cores in your system.

I waited for about an hour for it to complete compiling. Then I tried to test,

But there were errors, so I found I was again missing some of the dependencies. This was solved by installing DejaGnu.

Then the make -k check script worked fine. Finally, we need to install this in its final resting place:

To test the final installation, we may do

since we have installed it in /opt/. We should get something like the following: gcc-4.7 (GCC) 4.7.0 .

We may now change the symlinks and compile scripts to compile with this new version of GCC. Remember to check whether the linker is linking to the correct libraries.