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.
1 2 3 4 5 6 7 |
#!/bin/bash umask 0 mkdir -p /shared/tools/gcc/gcc-4.7.0 cd /shared/tools/gcc/gcc-4.7.0 wget http://projects.joelinoff.com/gcc-4.7.0/bld.sh chmod a+x bld.sh ./bld.sh 2>&1 | tee bld.log |
Simple Test Program: x.cc
If you want, you can create a simple program like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// Test the gcc 4.7.0 compiler. #include <iostream> #include <boost/algorithm/string.hpp> using namespace std; using namespace boost; int main() { string s1(" hello world! "); cout << "value : '" << s1 << "'" <<endl; to_upper(s1); cout << "to_upper() : '" << s1 << "'" <<endl; trim(s1); cout << "trim() : '" << s1 << "'" <<endl; return 0; } |
Then compile, link and run it as follows.
1 2 3 4 5 6 7 8 9 10 |
#!/bin/bash GHM="/shared/tools/gcc/gcc-4.7.0/rtf" GXX="${GHM}/bin/g++" # OR PATH="${GHM}/bin:${PATH}" export LD_LIBRARY_PATH="${GHM}/lib64" $GXX -O3 -Wall -o x.exe x.cc ./x.exe # Expected output # value : ' hello world! ' # to_upper() : ' HELLO WORLD! ' # trim() : 'HELLO WORLD!' |
or if you prefer make…
1 2 3 4 5 6 7 8 9 10 11 12 13 |
GHM="/home/jlinoff/work/gcc-4.7.0/rtf" GXX="${GHM}/bin/g++" # OR PATH="${GHM}/bin:${PATH}" all: x.exe ./x.exe clean: \rm -f *~ *exe %.exe : %.cc @export LD_LIBRARY_PATH="$(GHM)/lib64" ; \ $(GXX) -O3 -Wall -o $@ $< |
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!
This is great! Saved me a lot of time. Thank you!
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.
Will this and/or your other scripts work on CentOs 6? I am not having much luck with them…
I am not sure. I haven’t tried yet. My plan is to give it a shot sometime this week.
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.
Amazing! Very useful script. It would be nice to add SMP building with make -j N
Thank you. Excellent work.
I have trouble with ppl-0.12 but everything OK with ppl-0.11.2. Building gcc (4.7 and 4.6.3) have completed with error: missing -lpwl.
Thanks, that is great feedback. Which OS did you build on?
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.
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).
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?
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.
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.
Trying to use this on Centos 6.2 (x86_64)
Getting a fatal error about gnu/stubs-32.h no such file or directory
Wondering how to correct this?
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.
“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”
Thanks. This is the command to install the 32 bit version:
$ sudo yum install -y glibc_devel.i686
Hello, you should change mpfr-3.1.0.tar.bz2 to mpfr-3.1.1.tar.bz2!
The older version doesn’t exist anymore.
Thank you, I will do that when I post the script for 4.7.1.
This is most easily done by simply changing the line
http://www.mpfr.org/mpfr-current/mpfr-3.1.0.tar.bz2
to
http://www.mpfr.org/mpfr-current/mpfr-3.1.1.tar.bz2
then it works…
Thank you. It has been fixed in the script for 4.7.2.
i have run the script, the script creates only the directory structure without any executable file. i guess it couldn’t download something. i’m using centos 5.3
I have not tried an installation on CentOS 5.3. Did the script exit with a status other than 0?
Awesome, worked perfectly for GCC 4.7.2, Boost 1.51, and CentOS 5.2. Thanks!
Thank you for letting me know. I have updated the blog entry to reflect that.
I actually updated the blog for 4.7.2 not this one.
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]#
MPFR version changed.
Breaks download.
In script change:
http://www.mpfr.org/mpfr-current/mpfr-3.1.0.tar.bz2tohttp://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.bz2
Thanks for pointing that out. I will change the script later today.