Bash script to download, build and install gcc 4.6.2 and boost 1.48

I recently had to build gcc 4.6.2 on CentOS 5.5 and found it to be quite painful so I put together this script to do all of the work: http://projects.joelinoff.com/gcc-4.6.2/bld.sh.txt. I am releasing it 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.6.2/bld.sh if you want to download it directly using something like wget.

Disk Space Usage

Beware that building gcc-4.6.2 and boost-1.48 requires almost 4 GB of disk space. Here is the breakdown:

After the build is complete you can delete the archives and src directory trees to reclaim about 3.3GB of disk space.

Using bld.sh

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

Simple Test Program: x.cc

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

And then compile, link and run it as follows.

Final Thoughts

This script has been tested on CentOS 5.5 (x86_64).

I am in the process of testing it on Ubuntu 11.10 (x86_64).

UPDATE #1
The Ubuntu 11.10 build failed during the stage1 compilation of gcc because it could not find bits/predefs.h. That file is available under /usr/include/x86_64-linux-gnu so I expect that it would fairly easy to fix this by adding -I/usr/include/x86_64-linux-gnu to the command line using CPPFLAGS. I will try that and post an update.

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.6.2-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!

15 thoughts on “Bash script to download, build and install gcc 4.6.2 and boost 1.48”

  1. Hi!
    I have tried your bld.sh script to install gcc-4.6.2 on redhat release 5.7 with gcc 4.1.2 default and it worked very well. Later when I tried to run it on redhat 6.1 with default gcc 4.4.5 it didn’t work anymore it gives the error when installing ppl that it doesn’t find gmp. These are the last lines of the bld.log
    Do you have any ideas what I could try?
    Thanks

    checking for ld used by GCC… /usr/bin/ld
    checking if the linker (/usr/bin/ld) is GNU ld… yes
    checking for shared library run path origin… done
    checking how to link with libgmp… /data/mbotezat/gcc/gcc-4.6.2/rtf/lib/libgmp.so -Wl,-rpath -Wl,/data/mbotezat/gcc/gcc-4.6.2/rtf/lib
    checking how to link with libgmpxx… /data/mbotezat/gcc/gcc-4.6.2/rtf/lib/libgmpxx.so /data/mbotezat/gcc/gcc-4.6.2/rtf/lib/libgmp.so -Wl,-rpath -Wl,/data/mbotezat/gcc/gcc-4.6.2/rtf/lib -Wl,-rpath -Wl,/data/mbotezat/gcc/gcc-4.6.2/rtf/lib
    checking for the GMP library version 4.1.3 or above… no
    configure: error: Cannot find GMP version 4.1.3 or higher.
    GMP is the GNU Multi-Precision library:
    see http://www.swox.com/gmp/ for more information.
    When compiling the GMP library, do not forget to enable the C++ interface:
    add –enable-cxx to the configuration options.
    STATUS = 1

    1. Hmmm, GMP 5.0.3 should have been installed earlier in the process so there must be one of two problems: the GMP installation failed, or the GMP installation went someplace that the GCC configure can’t find. That latter problem could be occurring because of a change in how autoconf works or it could be that my script has a bug for that platform. It could even be an indicate of some other incompatibility (I saw something similar on Ubuntu 11.10).

      Since I have no experience with CentOS 6.x, I can’t comment specifically. Here are some general ideas.

      First check to see whether libgmp is in the area that you expect.

      Second, check to see whether the configuration setup is correct in the gcc area.

      You might also check to see if there are other errors or warnings in the log.

    2. To jlinoff: Nice job!!! This script is very useful, and I really appreciate your sharing.

      To ioana: The similar problem occurred when I run this script on CentOS 6.1 with a default gcc 4.4.5. I found that some configuration options of ppl can’t work appropriately on this kernel. For example, even if you specify the –with-gmp-prefix option, the linker can’t find the correct library files, libgmp.so and libgmpxx.so. This probably stems from the fact that there is a default gmp 4.3.1 on CentOS 6.1. Therefore, I specified the –libdir option instead. After I specified the –libdir option, the linker can find the correct library files which this script just built. However, I encountered the same error message as yours. I thought I can specify the –includedir option to resolve this problem but I failed. The compiler can’t find the correct header files, gmp.h and gmpxx.h. Fortunately,after adding the include directory into the environment variable, LD_LIBRARY_PATH, I can successfully install ppl and gcc 4.6.2 on CentOS 6.1. I hope this information can help you with the installation of your gcc 4.6.2.

      – Jason

  2. Great work. I already have gcc-4.6 installed in home directory. How to change this to just install boost. I could not see the option. Can you tell? Thanks.

    1. You should be able to simply install boost as specified on the boost.org site but here is how you could do it manually. This is typed basically from memory so please forgive any typos.

      Please let me know whether this works for you.

      1. Currently, I am using entire script to get both boost and gcc.
        I have gcc4.6.0 and 4.1 which I used to install your unmodified bld.sh script (for both boost and gcc). However, I get error:

        configure: error: Cannot find GMP version 4.1.3 or higher.
        ..When compiling the GMP library, do not forget to enable the C++ interface:
        add –enable-cxx to the configuration options.
        Can you please help in this regard. Let me know, if I should send the log file.

  3. Hi

    When we include java in enable langauges options getting the above error after running the script?

    –enable-languages=’c,c++,java’ in the script to enable libjava… it doesn’t work

    libtool: compile: /home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2/./gcc/xgcc -B/home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2/./gcc/ -B/home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/bin/ -B/home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/lib/ -isystem /home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/include -isystem /home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/sys-include -m32 -DHAVE_CONFIG_H -I. -I/home/myhome/srinivasa/gcc/gcc-4.6.2/src/gcc-4.6.2/libjava/classpath/native/jni/java-math -I../../../include -I/home/myhome/srinivasa/gcc/gcc-4.6.2/src/gcc-4.6.2/libjava/classpath/include -I/home/myhome/srinivasa/gcc/gcc-4.6.2/src/gcc-4.6.2/libjava/classpath/native/jni/classpath -I/home/myhome/srinivasa/gcc/gcc-4.6.2/src/gcc-4.6.2/libjava/classpath/native/jni/native-lib -I/home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/include -W -Wall -Wmissing-declarations -Wwrite-strings -Wmissing-prototypes -Wno-long-long -I/home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/include -g -O2 -m32 -MT gnu_java_math_GMP.lo -MD -MP -MF .deps/gnu_java_math_GMP.Tpo -c /home/myhome/srinivasa/gcc/gcc-4.6.2/src/gcc-4.6.2/libjava/classpath/native/jni/java-math/gnu_java_math_GMP.c -fPIC -DPIC -o .libs/gnu_java_math_GMP.o
    mv -f .deps/gnu_java_math_GMP.Tpo .deps/gnu_java_math_GMP.Plo
    /bin/sh ../../../libtool –tag=CC –mode=link /home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2/./gcc/xgcc -B/home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2/./gcc/ -B/home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/bin/ -B/home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/lib/ -isystem /home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/include -isystem /home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/sys-include -m32 -W -Wall -Wmissing-declarations -Wwrite-strings -Wmissing-prototypes -Wno-long-long -I/home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/include -g -O2 -m32 -module -version-info 0:0:0 -no-undefined -L/home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/lib -lgmp -avoid-version -m32 -o libjavamath.la -rpath /home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/lib/../lib/gcj-4.6.2-12 gnu_java_math_GMP.lo ../../../native/jni/classpath/jcl.lo
    libtool: link: /home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2/./gcc/xgcc -B/home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2/./gcc/ -B/home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/bin/ -B/home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/lib/ -isystem /home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/include -isystem /home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/sys-include -m32 -shared .libs/gnu_java_math_GMP.o ../../../native/jni/classpath/.libs/jcl.o -Wl,-rpath -Wl,/home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/lib -Wl,-rpath -Wl,/home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/lib -L/home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/lib /home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/lib/libgmp.so -m32 -m32 -m32 -Wl,-soname -Wl,libjavamath.so -o .libs/libjavamath.so
    /home/myhome/srinivasa/gcc/gcc-4.6.2/rtf/lib/libgmp.so: could not read symbols: File in wrong format
    collect2: ld returned 1 exit status
    make[8]: *** [libjavamath.la] Error 1
    make[8]: Leaving directory /home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2/x86_64-unknown-linux-gnu/32/libjava/classpath/native/jni/java-math'
    make[7]: *** [all-recursive] Error 1
    make[7]: Leaving directory
    /home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2/x86_64-unknown-linux-gnu/32/libjava/classpath/native/jni’
    make[6]: *** [all-recursive] Error 1
    make[6]: Leaving directory /home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2/x86_64-unknown-linux-gnu/32/libjava/classpath/native'
    make[5]: *** [all-recursive] Error 1
    make[5]: Leaving directory
    /home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2/x86_64-unknown-linux-gnu/32/libjava/classpath’
    make[4]: *** [all-recursive] Error 1
    make[4]: Leaving directory /home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2/x86_64-unknown-linux-gnu/32/libjava'
    make[3]: *** [multi-do] Error 1
    make[3]: Leaving directory
    /home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2/x86_64-unknown-linux-gnu/libjava’
    make[2]: *** [all-multi] Error 2
    make[2]: Leaving directory /home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2/x86_64-unknown-linux-gnu/libjava'
    make[1]: *** [all-target-libjava] Error 2
    make[1]: Leaving directory
    /home/myhome/srinivasa/gcc/gcc-4.6.2/bld/gcc-4.6.2′
    make: *** [all] Error 2
    STATUS = 2

    Regards,
    Srinivasa

  4. Hi
    Great work, but I still have some problems trying to compile it on CentOS 5.5 64bits with installed gcc 4.1.2-48 at ‘multilibs’ building step:

    # If this is the top-level multilib, build all the other
    # multilibs.
    /home/testGCC/gcc-4.6.2/bld/gcc-4.6.2/./gcc/xgcc -B/home/testGCC/gcc-4.6.2/bld/gcc-4.6.2/./gcc/ -B/home/testGCC/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/bin/ -B/home/testGCC/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/lib/ -isystem /home/testGCC/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/include -isystem /home/testGCC/gcc-4.6.2/rtf/x86_64-unknown-linux-gnu/sys-include -g -O2 -m32 -O2 -g -O2 -DIN_GCC -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED -fno-stack-protector -I. -I. -I../../.././gcc -I/home/testGCC/gcc-4.6.2/src/gcc-4.6.2/libgcc -I/home/testGCC/gcc-4.6.2/src/gcc-4.6.2/libgcc/. -I/home/testGCC/gcc-4.6.2/src/gcc-4.6.2/libgcc/../gcc -I/home/testGCC/gcc-4.6.2/src/gcc-4.6.2/libgcc/../include -I/home/testGCC/gcc-4.6.2/src/gcc-4.6.2/libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAVE_CC_TLS -DUSE_TLS -o _muldi3.o -MT _muldi3.o -MD -MP -MF _muldi3.dep -DL_muldi3 -c /home/testGCC/gcc-4.6.2/src/gcc-4.6.2/libgcc/../gcc/libgcc2.c \
    -fvisibility=hidden -DHIDE_EXPORTS
    In file included from /home/testGCC/gcc-4.6.2/bld/gcc-4.6.2/./gcc/include-fixed/features.h:361:0,
    from /usr/include/stdio.h:28,
    from /home/testGCC/gcc-4.6.2/src/gcc-4.6.2/libgcc/../gcc/tsystem.h:87,
    from /home/testGCC/gcc-4.6.2/src/gcc-4.6.2/libgcc/../gcc/libgcc2.c:29:
    /usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory
    compilation terminated.
    make[5]: *** [_muldi3.o] Error 1
    make[5]: Leaving directory /home/testGCC/gcc-4.6.2/bld/gcc-4.6.2/x86_64-unknown-linux-gnu/32/libgcc'
    make[4]: *** [multi-do] Error 1
    make[4]: Leaving directory
    /home/testGCC/gcc-4.6.2/bld/gcc-4.6.2/x86_64-unknown-linux-gnu/libgcc’
    make[3]: *** [all-multi] Error 2
    make[3]: Leaving directory /home/testGCC/gcc-4.6.2/bld/gcc-4.6.2/x86_64-unknown-linux-gnu/libgcc'
    make[2]: *** [all-stage1-target-libgcc] Error 2
    make[2]: Leaving directory
    /home/testGCC/gcc-4.6.2/bld/gcc-4.6.2′
    make[1]: *** [stage1-bubble] Error 2
    make[1]: Leaving directory `/home/testGCC/gcc-4.6.2/bld/gcc-4.6.2′
    make: *** [all] Error 2
    STATUS = 2

    Can you please help me? Let me know if I need more info.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.