Building GCC 4.7.0 on Debian Squeeze (Stable)

March 28, 2012

GCC 4.4 is the default compiler on Squeeze, and there’s nothing newer in the Backports. So, you can dirty up your system by installing some packages from sid or testing, of you can build your own compiler. Since 4.4 wasn’t sufficient for my needs, I decided to do the latter. I killed a day on this, but finally have something that works decently.

To start, create a directory like ~/gcc-4.7, and export it’s absolute path into an environment variable.

Note: this isn’t necessary, but it cleans up our configuration options. Depending on your use case, you might just choose to install to the /usr/local prefix, or even something more serious like /usr.

mkdir ~/gcc-4.7
export PROJECT_DIR=$(cd ~/gcc-4.7 && pwd && cd - &>/dev/null)

Get the Source Packages

Firstly, you’ll want to download all of the necessary packages. I created a directory for these in $PROJECT_DIR/sources:

mkdir $PROJECT_DIR/sources && cd !$
  1. PPL latest (0.12):
    wget http://bugseng.com/products/ppl/download/ftp/releases/LATEST/ppl-0.12.tar.gz
    
  2. CLooG 0.16.1:
    wget http://www.bastoul.net/cloog/pages/download/count.php3?url=./cloog-0.16.1.tar.gz
    
  3. MPC latest (0.9):
    wget http://www.multiprecision.org/mpc/download/mpc-0.9.tar.gz
    
  4. GMP latest (5.0.4):
    wget ftp://ftp.gmplib.org/pub/gmp-5.0.4/gmp-5.0.4.tar.bz2
    
  5. MPFR latest (3.1.0):
    wget http://www.mpfr.org/mpfr-current/mpfr-3.1.0.tar.bz2
    
  6. GCC 4.7.0:
    wget http://www.netgull.com/gcc/releases/gcc-4.7.0/gcc-4.7.0.tar.bz2
    

Okay, now unpack them. This should do the trick:

for file in *.tar.gz; do tar xzvf $file; done
for file in *.tar.bz2; do tar xjvf $file; done

Building the Pre-requisites

From here, you can mostly follow this documentation on building 4.7 for Mac OS X Lion. A couple of notable differences, though.

It’s good practice to build in a separate directory from the source. So I create a directory $PROJECT_DIR/build. Also at this time I create directory $PROJECT_DIR/output, which will be the install target for everything we build.

So let’s get right down to it.

Build GMP:

mkdir $PROJECT_DIR/build/gmp
cd !$
../../sources/gmp-5.0.4/configure --prefix=$PROJECT_DIR/output/
make && make install
cd -

Build MPFR:

mkdir $PROJECT_DIR/build/mpfr
cd !$
../../sources/mpfr-3.1.0/configure \
    --prefix=$PROJECT_DIR/output/  \
    --with-gmp=$PROJECT_DIR/output/
make && make install
cd -

Build MPC:

mkdir $PROJECT_DIR/build/mpc
cd !$
../../sources/mpc-0.9/configure     \
    --prefix=$PROJECT_DIR/output/   \
    --with-gmp=$PROJECT_DIR/output/ \
    --with-mpfr=$PROJECT_DIR/output/
make && make install
cd -

Build PPL:

mkdir $PROJECT_DIR/build/ppl
cd !$
../../sources/ppl-0.12/configure  \
    --prefix=$PROJECT_DIR/output/ \
    --with-gmp=$PROJECT_DIR/output/
make && make install
cd -

Build CLooG:

mkdir $PROJECT_DIR/build/cloog
cd !$
../../sources/cloog-0.16.1/configure \
    --prefix=$PROJECT_DIR/output/
    --with-gmp=$PROJECT_DIR/output/
make && make install
cd -

And that’s that!

Build GCC 4.70

Okay, so now it’s time for the main attraction, the compiler suite itself.

mkdir $PROJECT_DIR/build/gcc
cd !$
../../sources/gcc/configure          \
    --prefix=$PROJECT_DIR/output/    \
    --with-gmp=$PROJECT_DIR/output/  \
    --with-mpfr=$PROJECT_DIR/output/ \
    --with-mpc=$PROJECT_DIR/output/  \
    --program-suffix=-4.7            \
    --enable-cloog-backend=isl       \
    --with-ppl=$PROJECT_DIR/output/  \
    --with-cloog=$PROJECT_DIR/output/

export LD_LIBRARY_PATH=$PROJECT_DIR/output/lib/
make && make install
cd -

Note the LD_LIBRARY_PATH line. That’s crucial if you’re not installing to the default location, /usr/local, because your libraries won’t be in the PATH specified in the ld.so.conf files.

The --program-suffix=-4.7 flag is of course a matter of personal taste, and can be omitted if you like.

It may be possible to use a value for --enable-cloog-backend other than isl, but that seemed to work.

Also, there are of course hundreds of other reasonable GCC configurations possible. Your mileage may vary, but this is pretty vanilla, and it produces a working toolchain. (Which is a nice quality to it.)

Thanks for reading!

References

17 Responses to “Building GCC 4.7.0 on Debian Squeeze (Stable)”

  1. [...] done the dirty work, and have built GCC 4.7.0 on Debian Squeeze. Tales of the adventure, here: http://nosemaj.org/debian-gcc-4-7 So now my question is, is there any chance to remove the explicit dependencies, so I can install [...]

  2. vairavan says:

    I encountered this error while doing a make on gcc.

    /usr/lib/../lib/crti.o: could not read symbols: File in wrong format

    locate crti.o says there is two crti.o’s

    /usr/lib/crti.o
    /usr/lib64/crti.o

    I guess it should read the 64 bit rather than reading the 32 bit.. what should i do now?

  3. vairavan says:

    sorry that is actually a link to the 64 bit, then why this error?

  4. [...] source. So the configure line will start this way : ../gcc-4.70/configure — A build example http://nosemaj.org/debian-gcc-4-7 [...]

  5. eloj says:

    When compiling gmp, had to add –enable-cxx
    When compiling cloog, had to use –with-gmp-prefix=…

  6. Monty says:

    Also add –disable-multilib, if you’re on x86_64.

  7. Hi, when I tried to compile CLooG I got the following error:

    hecking for sys/resource.h… yes
    checking which isl to use… bundled
    checking which gmp to use… system
    checking gmp.h usability… no
    checking gmp.h presence… no
    checking for gmp.h… no
    configure: error: Can’t find gmp headers.
    root@asus:/usr/local/gcc-4.7/build/cloog#

    I also tried to manipulate with –with-gmp-include=… switch but it was not the solution. Here are tips that I tried to use: http://stackoverflow.com/questions/10446843/installed-gmp-but-cant-see-it.

    I got the error after:

    ../../sources/cloog-0.16.1/configure \
    –prefix=$PROJECT_DIR/output/ –with-gmp-include=/usr/local/gcc-4.7/output/include/
    –with-gmp=$PROJECT_DIR/output/ –disable-multilib

    Could someone give me a hint what is incorrect? I’ll be very glad for all answers.

    Greetings,

  8. doober says:

    It’s because it should be:

    –with-gmp-prefix=

    not

    –with-gmp=

    as eloj said

  9. [...] method than the example gcc-3.2. # 1 : Example gcc-4.7 : The procedure is valid for 4.6.x too .. http://nosemaj.org/debian-gcc-4-7 [...]

  10. Phrozenbit says:

    I Had to install zip and unzip somewhere along the way, had something to do with Java libraries that needed to compile.

    apt-get install zip unzip

    will do the trick on a clean Debian 6.0.5 AMD64 installation.

    Thanks for the tutorial!

  11. [...] The command : 'cat /etc/issue' will reply with (K)ubuntu <version>. The gcc at http://gcc.gnu.org/ is source code, not a binary package. Building gcc-4.7, example : http://nosemaj.org/debian-gcc-4-7 [...]

  12. [...] I found an excellent tutorial to do this here: (everything below will assume you are following these steps) NoseMaj Debian GCC 4.7 Tutorial [...]

  13. [...] ). Suggest : Use option –program-suffix=47 … Then you can use –prefix=/usr/ Build example http://nosemaj.org/debian-gcc-4-7 Or better : Build the Debian packages, suggested by @caravel. $ apt-get -b source gcc-4.7=4.7.1-6 [...]

  14. Darko says:

    Thanks for the tutorial! It really helped me!

  15. Hernan says:

    Hello!
    In the step Build CLooG:
    with the command: ../../sources/cloog-0.16.1/configure –prefix=$PROJECT_DIR/output/ –with-gmp=$PROJECT_DIR/output/ make && make install

    I had some problems. First if I put all that in separated lines (as it is indicated, with the command make && make install in the following line) it throw the following error:

    checking which isl to use… bundled
    checking which gmp to use… system
    checking gmp.h usability… no
    checking gmp.h presence… no
    checking for gmp.h… no
    configure: error: Can’t find gmp headers.

    If I put everything on the same line, I obtain:

    checking whether we are using the GNU C compiler… yes
    checking whether gcc accepts -g… yes
    checking for gcc option to accept ISO C89… none needed
    checking for style of include used by make… GNU
    checking dependency style of gcc… gcc3
    checking whether ln -s works… yes
    checking whether make sets $(MAKE)… (cached) yes
    checking for cd… no
    checking build system type… Invalid configuration `make': machine `make’ not recognized
    configure: error: /bin/bash ../../sources/cloog-0.16.1/autoconf/config.sub make failed

  16. John Feltz says:

    Just a friendly FYI: It’s 2014 and gcc-4.7.4 has been just released. Instead of source installing requisites (mpfr, mpr etc.), users still on squeeze should attempt a install of the related lib-*-dev files through the apt package system instead. This worked for me.

    Cheers,
    John

Leave a Reply