This guide is written as to aid CHPC users who are struggling to compile the GCC version required for their codes. For the official guide on compiling GCC please visit the GCC website. This guide documents how GCC 4.7.1 would be built on the Sun Tsessbe Cluster login node, after the August 2012 upgrades.
This guides use the temporary working /tmp/$USER/gcc_build, the installation directory of $HOME/local
Before you begin, comment out all alterations to your ~/.bashrc file (example ). Then log out and in again and you should see, should see the following from the shell
$ gcc -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: /usr/local/gcc/gcc-4.3.4/configure --prefix=/opt/gridware/gcc-4.3 --disable-multilib Thread model: posix gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)
Note on the lib folder naming conventions, the standard in 2012 is to have libraries 64 bit by default, and some 32 bit libraries as well. In Ubuntu 12.04 for example, the following library folder name convention is used
However, on the login node which is little older, its the other way round. The lib folder refers to 32 bit libraries by default, while the lib64 is for 64 bit libraries. ie its the chpc nodes have the following naming convention
So when you install software, which is 64 bit (default these days) remember you want to install it in the lib64 and not the lib folder, as the lib64 folders are searched first. ie use the following compilation flag –libdir=$HOME/local/lib64
The latest version of of these libraries are going to be setup in the your local directory
$ ld --version GNU ld version 18.104.22.168.6-20.el5_8.3 20061020 $ ld --verbose | grep SEARCH SEARCH_DIR("/usr/x86_64-redhat-linux/lib64"); SEARCH_DIR("/usr/local/lib64"); SEARCH_DIR("/lib64"); SEARCH_DIR("/usr/lib64"); SEARCH_DIR("/usr/x86_64-redhat-linux/lib"); SEARCH_DIR("/usr/lib64"); SEARCH_DIR("/usr/local/lib"); SEARCH_DIR("/lib"); SEARCH_DIR("/usr/lib");
Install the latest version of GNU bin utils, as follows
$ mkdir -p /tmp/$USER/gcc_build $ cd /tmp/$USER/gcc_build $ wget http://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.gz $ tar -xf binutils-2.22.tar.gz $ mkdir binutils-2.22/BUILD $ cd binutils-2.22/BUILD $ mkdir $HOME/local $ ../configure --prefix=$HOME/local --libdir=$HOME/local/lib64 $ make # takes a couple of minutes $ make check 1> make.check 2>&1 # should take 5 minutes to complete
If all tests are passed:
$ grep -i -e pass -e fail -e summary make.check === binutils Summary === # of expected passes 94 === gas Summary === # of expected passes 625 === ld Summary === # of expected passes 703 # of expected failures 61 ./test-demangle: 844 tests, 0 failures
Add the following to bashrc file,
export PATH=$HOME/bin:$PATH export PATH=$HOME/local/bin:$PATH unset LD_LIBRARY_PATH # the default value is non-sensical now..
log in and out again, and
$ ld -v GNU ld (GNU Binutils) 2.22
And neatly enough, now your local paths have been added to the ld search pash
$ ld --verbose | grep SEARCH SEARCH_DIR("/export/home/$USER/local/x86_64-unknown-linux-gnu/lib64"); SEARCH_DIR("/export/home/$USER/local/lib64"); SEARCH_DIR("/usr/local/lib64"); SEARCH_DIR("/lib64"); SEARCH_DIR("/usr/lib64"); SEARCH_DIR("/export/home/$USER/local/x86_64-unknown-linux-gnu/lib"); SEARCH_DIR("/export/home/$USER/local/lib"); SEARCH_DIR("/usr/local/lib"); SEARCH_DIR("/lib"); SEARCH_DIR("/usr/lib");
SideNote : the LD_LIBRARY_PATH variable does not effect the output of ld –verbose | grep SEARCH
Take moment the reader though the libtool configuration,
$libtool --config | less $libtool --version ltmain.sh (GNU libtool) 1.5.22 (1.1220.2.365 2005/12/18 22:14:06)
$ cd /tmp/$USER/gcc_build $ wget ftp://ftp.gnu.org/gnu/libtool/libtool-2.4.2.tar.gz $ tar -xf libtool-2.4.2.tar.gz $ cd libtool-2.4.2 $ mkdir BUILD $ cd BUILD $ ../configure --prefix=$HOME/local --libdir=$HOME/local/lib64 $ make $ make check 1> make.check 2>&1 # takes about 10 minutes, so do inside screen and tail output... $ make install
check everything out
$libtool --version libtool (GNU libtool) 2.4.2 $libtool --config | less
A table showing what tools and package for building GCC, and what is available on the cluster login node (this is where GCC will be built)
|Prerequisite||Version Required (or later)||Available|
|ISO C90 compiler||GCC binary version 2.95||gcc 4.3.4|
|A “working” POSIX compatible shell, or GNU bash||bash available|
|awk||GNU awk version 3.1.5||GNU awk version 3.1.5|
|jar, or InfoZIP||?|
ClooG note, online docs and compiler checks differ on this one. Online docs say ClooG 0.17 (built using the ISL 0.10) is required, where gcc configure checks for Cloog 0.16.X. But the conpiler does have an option to ignore Cloog version, so i really dont know. For this gcc build guide, i used the 0.17.0 ISL version of Cloog.
Also note from http://gcc.gnu.org/install/prerequisites.html “While any sufficiently new version of required tools usually work, library requirements are generally stricter. Newer versions may work in some cases, but it's safer to use the exact versions documented”
The gcc-4.2.4 c and c++ compilers are going to be used to build the require libraries. The gcc-4.2 branch is the last gcc sub version, which does require the GMP, MPFR or MPC libraries.
$ cd /tmp/$USER/gcc_build $ wget http://ftp.gnu.org/gnu/gcc/gcc-4.2.4/gcc-4.2.4.tar.bz2
$ tar -xf gcc-4.2.4.tar.bz2
$ cd gcc-4.2.4 $ mkdir BUILD $ cd BUILD $ mkdir /tmp/$USER/gcc_build/usr $ ../configure --prefix=/tmp/$USER/gcc_build/usr --libdir=/tmp/$USER/gcc_build/usr/lib64
build inside a screen session
$ screen $ make > make.out 2>&1 # crtl-a crtl-d to detach screen $ tail -f make.out #to watch compilation progress # after the make is complete, close the screen session by $ screen -r, then ctrl-d
This compiliation took just under 2 hours to complete, when this guide was written. Future work, disabling the build of lib java will probabily reduce the build time to less then an hour
Before continuing its probabily a good idea to test the gcc build ….
$ screen $ make -k check > make.check 2>&1 # ctrl-a crtl-d $ tail -f make.check
Tests took about 2 hours to complete.
Test results, when writing this guide
$ grep -e '# of ' -e Summary /tmp/$USER/gcc_build/gcc-4.2.4/BUILD/make.check === gcc Summary === # of expected passes 42433 # of expected failures 127 # of unresolved testcases 1 # of untested testcases 28 # of unsupported tests 405 === g++ Summary === # of expected passes 13564 # of expected failures 67 # of unsupported tests 106
Only continue with this guide if all the tests are passed
Install the compliled gcc if
$ make install
Next the environment variables affecting GCC 4.2.4 need to be set. Add the following lines to your .bashrc script file,
# temporary gcc 4.2.4 build export PATH=/tmp/$USER/gcc_build/usr/bin:$PATH export LD_LIBRARY_PATH=/tmp/$USER/gcc_build/usr/lib64:/tmp/$USER/gcc_build/usr/lib export C_INCLUDE_PATH=$HOME/local/include export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH
Note, the $HOME/local/ additions are for the libraries which going to be built using gcc 4.2.4 for the latest gcc version.
then logout and in again. You should see the following
$ gcc -v ... gcc version 4.2.4
Also check your include paths, and library paths using
$ echo | gcc -v -x c -E - $ echo | gcc -v -x c++ -E -
$ gcc -Wl,--verbose | less
The libraries required all follow the same build procedure,
1. download and extract 2. configure 3. make 4. make check, and in some cases 5. make install
So a helper script is used to help automate the process. THe helper script download_and_install_from_source.sh, can be download as follows,
$ mkdir $HOME/local/bin $ cd $HOME/local/bin $ wget http://dymond.co.za/download_and_install_from_source.sh $ chmod +x download_and_install_from_source.sh
return to your home folder, and you should see
$ cd ~/ $ download_and_install_from_source.sh Usage: download_and_install_from_source.sh TAR_URL BUILD_DIR CONFIGURE_OPTIONS [INSTALL_DIR]
This helper script, is used in the rest of the guide. DO NOT USE THIS SCRIPT BLINDLY WITH OUT READING THE APPS DOCUMENTATION AND CONFIGURATION OPTIONS.
GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating point numbers.
$ cd /tmp/$USER/gcc_build $ wget ftp://ftp.gmplib.org/pub/gmp-5.0.5/gmp-5.0.5.tar.bz2 $ tar -xf gmp-5.0.5.tar.bz2 $ cd gmp-5.0.5 $ mkdir BUILD $ cd BUILD $ ../configure --prefix=$HOME/local/gcc_libs --enable-cxx $ make $ make check $ make install
OR simply use our helper script
$ download_and_install_from_source.sh ftp://ftp.gmplib.org/pub/gmp-5.0.5/gmp-5.0.5.tar.bz2 \ /tmp/$USER/gcc_build "--enable-cxx --libdir=$HOME/local/lib64" $HOME/local
Assert that everyting went okay. When the download_and_install_from_source.sh script finished, it outputs the make check results. You should see a whole bunch of passes and no fails. Do this for the following library builds as well.
Finally copy the libraries to the gcc 4.2.4 of search path folder
$ cp -v $HOME/local/lib64/libgmp* /tmp/$USER/gcc_build/usr/lib64/
gcc and the linker search the 64 bit library folders first then the normal (32 bit folders afterwards (check out $ ld –verbose ). By default the latest versions of gmp install there 64 bit libraries under the lib folder and the lib64 folder. Which kind of makes sense; i.e. in the future is there going to need to be lib256 folder?
The problem is that on the login node gmp in installed in the /usr/lib64 folder. So this folder is found first using the linker and gcc compared to the /usr/lib folder for example. That is why the compiled libraries are installed and copied to the 64 bit folders.
The MPFR library is a C library for multiple-precision floating-point computations with correct rounding
$ download_and_install_from_source.sh http://www.mpfr.org/mpfr-current/mpfr-3.1.1.tar.gz \ /tmp/$USER/gcc_build "--libdir=$HOME/local/lib64" $HOME/local $ cp -v $HOME/local/lib64/libmpfr* /tmp/$USER/gcc_build/usr/lib64/
Gnu MPC is a C library for the arithmetic of complex numbers with arbitrarily high precision and correct rounding of the result
$ download_and_install_from_source.sh http://www.multiprecision.org/mpc/download/mpc-1.0.tar.gz \ /tmp/$USER/gcc_build "--libdir=$HOME/local/lib64" $HOME/local $ cp -v $HOME/local/lib64/libmpc* /tmp/$USER/gcc_build/usr/lib64/
The Parma Polyhedra Library (PPL) provides numerical abstractions especially targeted at applications in the field of analysis and verification of complex systems.
This one takes a while, so the use screen is recommened:
$ screen $ download_and_install_from_source.sh \ http://bugseng.com/external/ppl/download/ftp/releases/0.11.2/ppl-0.11.2.tar.bz2 \ /tmp/$USER/gcc_build \ "--enable-watchdog --libdir=$HOME/local/lib64" \ $HOME/local
detach_screen, and come back in 3 hours. To watch the progress use tail
$ tail -f /tmp/$USER/gcc_build/ppl-0.11.2/BUILD/make.out #for the building $ tail -f /tmp/$USER/gcc_build/ppl-0.11.2/BUILD/make.check # for the testing
make, takes 15 minutes make ckeck, takes 3 hours 15 minutes
copy libraries, to gcc 4.2.4 search path
$ cp -v $HOME/local/lib64/libp* /tmp/$USER/gcc_build/usr/lib64/
First ISL needs to be installed,
$ download_and_install_from_source.sh \ ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.10.tar.bz2 \ /tmp/$USER/gcc_build "--libdir=$HOME/local/lib64" $HOME/local $ cp -v $HOME/local/lib64/libisl* /tmp/$USER/gcc_build/usr/lib64/
CLooG is a free software and library to generate code for scanning Z-polyhedra
$ download_and_install_from_source.sh \ http://www.bastoul.net/cloog/pages/download/cloog-0.17.0.tar.gz \ /tmp/$USER/gcc_build "--with-isl=system --libdir=$HOME/local/lib64 --with-bits=gmp" $HOME/local $ cp -v $HOME/local/lib64/libcl* /tmp/$USER/gcc_build/usr/lib64/
With the required libraries now available, the main GCC build can begin.
$ cd /tmp/$USER/gcc_build $ wget http://www.mirrorservice.org/sites/ftp.gnu.org/gnu/gcc/gcc-4.7.1/gcc-4.7.1.tar.bz2 $ tar -xf gcc-4.7.1.tar.bz2
$ cd gcc-4.7.1/ $ mkdir BUILD $ cd BUILD $ ../configure --prefix=$HOME/local --disable-cloog-version-check \ --enable-cloog-backend=isl --libdir=$HOME/local/lib64 \ --with-mpc-include=$HOME/local/include --with-mpc-lib=$HOME/local/lib64 \ --with-mpfr-include=$HOME/local/include --with-mpfr-lib=$HOME/local/lib64 \ --with-gmp-include=$HOME/local/include --with-gmp-lib=$HOME/local/lib64 \ --with-ppl-include=$HOME/local/include --with-ppl-lib=$HOME/local/lib64 \ --with-cloog-include=$HOME/local/include --with-cloog-lib=$HOME/local/lib64
The following languages will be built: c,c++,fortran,java,lto,objc *** This configuration is not supported in the following subdirectories:
gnattools target-libada target-libgo (Any other directories should still work fine.)
Once the configuration is complete, use Make to build GCC
$ screen $ make > make.out 2>&1 # detach screen using ctrl-a crtl-d $ tail -f make.out
Expect the build to take about 2 hours to complete.
The benefit about this screen approach beyond saving you grey hairs, is that if ssh connection is lost or you close terminal, the compilation job will keep going. The compilation can take multiple hours… Beware though, the screen session uses your default environmental variables defined in your .bashrc file.
When make encounters an error and aborts the stating refer to config.log for further information. The trick is find the folder make was in when it threw that error. This can be done by inspecting the last command executed before make halted. the ls command with the -lh flag can also be used to find which folder was modified last.
Once the folder is found, read through the config.log file to get further information on the error. If nessary, take the config file contents available in the configure.log file, and paste them into a temporary file ie. config_debug.c and rerurn the broken xonfigure command using that file. A big help here is to add the -v flag to the xgcc compiler.
Test your gcc build before installing it.
$ cd /tmp/$USER/gcc_build/gcc-4.7.1/BUILD $ screen $ make -k check > make.check 2>&1 # detach screen using ctrl-a ctrl-d $ tail -f make.check
Testing took 3hrs 30 minutes
After the testing was completed, i had the following results
$ grep -e '# of ' -e Summary /tmp/$USER/gcc_build/gcc-4.7.1/BUILD/make.check === gcc Summary === # of expected passes 87683 # of unexpected failures 37 # of unexpected successes 40 # of expected failurea 273 # of unsupported tests 1262 === g++ Summary === # of expected passes 48687 # of unexpected failures 8 # of expected failures 286 # of unsupported tests 558 === gfortran Summary === # of expected passes 41001 # of expected failures 56 # of unsupported tests 69 === objc Summary === # of expected passes 2988 # of expected failures 6 # of unsupported tests 74 === libstdc++ Summary === # of expected passes 8900 # of expected failures 43 # of unsupported tests 145 === libmudflap Summary === # of expected passes 1905 # of unexpected failures 1 === libffi Summary === # of expected passes 1634 # of expected failures 10 # of unsupported tests 55 === libjava Summary === # of expected passes 2574 === boehm-gc Summary === # of expected passes 12 # of unsupported tests 1 === libgomp Summary === # of expected passes 2998 === libitm Summary === # of expected passes 26 # of expected failures 3 # of unsupported tests 1
If the testing results are acceptable for your intended applications, proceed with the installation.
from inside the gcc 4.7.1 build directory
$ make install
Remove all the lines added to your rc file since the start of this guide, and replace them with
export PATH=$HOME/bin:$HOME/local/bin:$PATH export LD_LIBRARY_PATH=$HOME/local/lib64
log in and out again, and
$ gcc -v Target: x86_64-unknown-linux-gnu ... Thread model: posix gcc version 4.7.1 (GCC)
also check out your default gcc paths for including and libraries
$ echo | gcc -v -x c -E - $ echo | gcc -v -x c++ -E -
check the ld loads paths as well
$ ld --verbose | grep SEARCH
BIG NB, THE LIB64 FOLDERS ARE SEARCHED FIRST. So if you install new libraries which by default these days are 64 bit and go the lib folder, and the system also has an installed version in the lib64 folder. The systems old version in a lib64 folder is selected before your newer version. So to be safe, when you install new software, use the following options
size of install
$ du -sh $HOME/local 1.2G
clean up your build directory
$ rm -r /tmp/$USER/gcc_build