Building GCC from trunk on Ubuntu 12.04

The current development version of GCC lives in the trunk of a subversion repository.  It is fairly easy to build on Ubuntu, however there are some dependencies that have to be met.  As it’s often handy to have the latest ‘bleeding edge’ version of GCC around (for verifying compiler bugs), I’ve written out the procedure below.

  1. Install the basic dependencies.

    $ sudo apt-get install gawk flex bison g++-multilib libmpc-dev libmpfr-dev libgmp-dev

  2. Build and install CLooG and ISL. The version of ISL included in CLooG 0.17.0 is too old, so we have to replace it before building.

    $ wget
    $ tar -xzf cloog-0.17.0.tar.gz
    $ cd cloog-0.17.0
    $ rm -rf isl
    $ wget
    $ tar -xjf isl-0.10.tar.bz2
    $ mv isl-0.10 isl
    $ ./configure –prefix=/usr/local/gcc-trunk –with-bits=gmp
    $ export LD_LIBRARY_PATH=/usr/local/gcc-trunk:$LD_LIBRARY_PATH
    $ make -j4
    $ sudo make install
    $ cd ..

  3. GCC itself is quite large (over 1GB uncompressed). Unless you’re on a fast connection, expect the checkout from SVN to take a while. An alternative is to download a bi-weekly ‘snapshot’– they’re not quite as up-to-date but the download process is a lot faster.

    $ svn checkout svn:// gcc-trunk

  4. Building GCC is a lengthy process. By explicitly defining the languages to build (C,C++,Objective C/C++ and Fortran), you can avoid building Java which more than doubles the build-time. As it is the build takes more than half an hour on a quad core i7 (2.8GHZ).  To speed up the compiler itself, you can add ‘–disable-checking‘ which disables additional runtime checking for development versions of the compiler.

    $ ../gcc-trunk/configure –prefix=/usr/local/gcc-trunk –enable-languages=c,c++,objc,obj-c++,fortran,lto –disable-checking –with-cloog=/usr/local/gcc-trunk –with-isl=/usr/local/gcc-trunk
    $ make -j4 bootstrap-lean
    $ sudo make install
    $ cd ..

  5. The new compiler will be installed as ‘gcc’ in ‘/usr/local/gcc-trunk/bin/gcc’. I usually symlink it to ‘/usr/local/bin/gcc-trunk’. Note that you must update $LD_LIBRARY_PATH to include /usr/local/gcc-trunk/lib (bashrc is often a good place to do this), or gcc will fail to execute with a runtime linker error.

Comments are closed.