Bash script to install gcc 4.7.0 and boost 1.49

I recently wanted to build gcc 4.7.0 on CentOS 5.5 to get access to more C++11 features so I put together this script to do all of the work. It is released in text mode so that you can cut-n-paste it from the web page. The shell version is also available: http://projects.joelinoff.com/gcc-4.7.0/bld.sh if you want to download it directly using a tool like wget.

The full installation of gcc-4.7.0 and boost-1.49 requires about 4GB of disk space. After the build is complete you can delete the archives, bld and src directory trees to reclaim about 3.4GB of disk space.

On 2012-04-14 I updated the script to install binutils-2.22 as well. You can disable it by simply commenting out line 139.
On 2012-09-22 I added page for installing gcc-4.7.2 and boost 1.51.0 here.

Using bld.sh

Here is how you might use build script described above to install gcc-4.7.0 and boost-1.49 on your system.

Simple Test Program: x.cc

If you want, you can create a simple program like this:

Then compile, link and run it as follows.

or if you prefer make…

Final Thoughts

This script has been tested on CentOS 5.5.

Note that I decided to use the latest version CLooG (0.17.0) so I had to put in a small hack to fix the gcc/g++ source code. Specifically I had to change LANGUAGE_C to CLOOG_LANGUAGE_C in the <gcc-4.7.0-source>/gcc/graphite-clast-to-gimple.c to track the same change in CLooG. This hack is done automatically by the script. I also had to turn off version checking because it specifically requires 0.16.0.

Please report problems or suggestions via the comments section.

Enjoy!

31 thoughts on “Bash script to install gcc 4.7.0 and boost 1.49

    1. jlinoff Post author

      I am glad to hear that it helped you. Today I updated it to build binutils-2.22 which might be interesting if you want to use the new gold linker.

  1. Pingback: gcc 4.7.0 bash install script updated to support binutils-2.22 | Joe's Blog

      1. jlinoff Post author

        I was able to demonstrate that my gcc-4.7.0 script does not work correctly on CentOS 6.2. The error that I saw was:

        configure: error:
        The following requested languages could not be built: c++,lto
        Supported languages are: c,java

        I am not sure what is going on and will investigate as soon as I can.

        1. Vitt

          CentOS 5.8 + kernel-ml-2.6.39-4.1.el5.elrepo + myself binutils-2.22 package (needed me for compiling with new instructions fma4, xop, avx).
          First I local built gcc-4.6.2 using your previos bld.sh script. So I got a working version gcc-4.6.2 and found libpwl.a in a directory /rtf/lib. Then I set environment variables and tried to build gcc-4.6.3 and gcc-4.7.0 with new gcc-4.6.2. Building ppl-0.12 has not made libpwl.a library and building gcc comleted with error.
          By the way, I build gfortran too (–enable-languages=’c,c++,fortran’) and use –disable-multilib for gcc.

    1. jlinoff Post author

      Thanks, that is a great idea. I will update it after I get it working for CentOS 6.2. I am working on that now (as a background task).

  2. Cry

    This script was super useful. Thanks!

    Any chance of adding -j options to make and b2 as in:

    docmd $ar make -j $JOBS
    and
    docmd $ar ./b2 -j$JOBS

    Also, I needed to specify –build-type=complete –build-type=complete –layout=versioned install

    I also manually build the latest icu release. Any chance in adding that in? Also mpi support for boost?

    1. jlinoff Post author

      Thanks, that is a good idea. It was also mentioned by Vitt in a previous post. I will add that capability in the next release.

      1. Cry

        Doh! Indeed he did mention adding -j support. Despite what the docs hint at, if you pass certain options in on the b2 command, and then separately, do a b2 install, those options might be lost. I found that they can be done together, more easily:

        docmd $ar ./b2 -j40 –build-type=complete –layout=versioned install

        Also, adding in icu to your scripts would be great. The one catch is that icu is a “bad doobee” in that the untar doesn’t include the versions…so it takes a bit more to put it into your script.

    1. jlinoff Post author

      I haven’t gotten it to work on CentOS 6.2 yet. Unfortunately I have had to focus on other areas will not be able to get back to this for awhile. Please let me know if you figure out how to get it working.

    2. Vitt

      “This error message shows up on the 64 bit systems where GCC/UPC multilib feature is enabled, and it indicates that 32 bit version of libc is not installed. There are two ways to correct this problem:
      1. Install 32 bit version of glibc (e.g. glibc-devel.i686 on Fedora, CentOS, ..)
      or
      2. (not recommended) Disable ‘multilib’ build by supplying “–disable-multilib” switch on the compiler configuration command”

  3. Trevor Creary

    I get a gmp.h not found message when I run the script. Any ideas to get over this hurdle? This is a new server install

    [root@s16389982 tools]# checking format of `long double’ floating point… IEEE extended, little endian
    > checking for TLS support… yes
    > checking for gmp.h… no
    > configure: error: gmp.h can’t be found, or is unusable.
    [root@s16389982 tools]#

  4. Pingback: Cross-compilation for Raspberry Pi in GCC. Where to start? - ARM Solutions - Developers Q & A

Leave a Reply