This is an old revision of the document!
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 guide is written for installing gcc 4.7.1 compilers for c,c++,fortran,objc.
Before you begin, make sure your bash environmental variable are set to their defaults. i.e. All additions to the ~/.bashrc file (example ), should be commented out. You should see the following from the shell
$ gcc --version gcc (GCC) 4.1.2
Also, this guide use the /tmp folder on the login node as the working directory to save disk space in your home directory.
Finally note that, all binaries and libraries are installed home directory, i.e prefix=$HOME/usr.
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 |
| GNAT | ? | ? |
| A “working” POSIX compatible shell, or GNU bash | bash available | |
| awk | GNU awk version 3.1.5 | GNU awk version 3.1.5 |
| GNU binutils | ? | |
| gzip | 1.2.4 | 1.3.5 |
| gzip2 | 1.0.2 | 1.0.3 |
| GNU tar | 1.14 | 1.15.1 |
| Perl | 5.6.1 | 5.8.8 |
| jar, or InfoZIP | ? | |
| GMP Library | 4.3.2 | 4.1.3 |
| MPFR Library | 2.4.2 | No |
| MPC Library | 0.8.1 | No |
| PPL Library | 0.11.1 | No |
| ClooG Library | 0.16.X | No |
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”
All the gcc_libs are going to be stored in the $HOME/usr/gcc_libs folder, if that folder doesn't exist,
$ mkdir -p $HOME/usr/gcc_libs
However to compile these libraries, we are going to need c++ compilers …
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.
create the temporary directory to compile the required codes
$ mkdir -p /tmp/$USER/gcc_build $ cd /tmp/$USER/gcc_build
download nessary files
$ wget http://ftp.gnu.org/gnu/gcc/gcc-4.2.4/gcc-core-4.2.4.tar.bz2 $ wget http://ftp.gnu.org/gnu/gcc/gcc-4.2.4/gcc-g++-4.2.4.tar.bz2 $ wget http://ftp.gnu.org/gnu/gcc/gcc-4.2.4/gcc-testsuite-4.2.4.tar.bz2
uncompress all
$ tar -xf gcc-core-4.2.4.tar.bz2 $ tar -xf gcc-g++-4.2.4.tar.bz2 $ tar -xf gcc-testsuite-4.2.4.tar.bz2
or
$ for archive in *.tar.bz2 ; do tar -xf $archive ; done
configure
$ cd gcc-4.2.4 $ mkdir BUILD $ cd BUILD $ mkdir /tmp/$USER/gcc_build/usr $ ../configure --prefix=/tmp/$USER/gcc_build/usr
build inside a screen session
$ screen $ make > make.out 2>&1 # 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 40 minutes to complete, when this guide was written.
Before continuing its probabily a good idea to test the gcc build ….
$ screen $ make -k check > make.check 2>&1 # ctrl-d $ tail -f make.check
Tests took about 50 minutes to complete.
Test results
$ 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
=== libstdc++ Summary ===
# of expected passes 4478
# of unexpected failures 7
# of unexpected successes 1
# of expected failures 14
=== libmudflap Summary ===
# of expected passes 1814
=== libgomp Summary ===
# of expected passes 496
which is all good :)
Installed the compliled gcc if passed the testing phase
$ make install
finally, update your enviromental variables. Add the follow to your .bashrc 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:$HOME/usr/gcc_libs/lib:$LD_LIBRARY_PATH #add library flags, for future compliations export LDFLAGS="-L/tmp/$USER/gcc_build/usr/lib64 -L/tmp/$USER/gcc_build/usr/lib -L$HOME/usr/gcc_libs/lib" #add include folder for headers export CPPFLAGS="-I/tmp/$USER/gcc_build/usr/include -I$HOME/usr/gcc_libs/include"
then logout and in again. You should see the following
$ gcc -v ... gcc version 4.2.4
The libraries required all follow the same build procedure, so a helper script is used to help automate the process. THe helper script download_and_install_from_source.sh, which put in by $HOME/bin folder is as follows
#! /usr/bin/env bash
#
# Script to install software from source, which requires the following steps
# 1. download and extract
# 2. configure
# 3. make
# 4. make check
# 5. make install
EXPECTED_ARGS=4
E_BADARGS=65
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` TAR_URL BUILD_DIR CONFIGURE_OPTIONS
INSTALL_DIR"
exit $E_BADARGS
fi
SOURCE_URL=$1
SOURCE_ARCHIVE=`basename $1`
SOURCE_FOLDER=${SOURCE_ARCHIVE%.*}
SOURCE_FOLDER=${SOURCE_FOLDER%.*}
echo source folder $SOURCE_FOLDER
BUILD_DIR=$2
BDIR=BUILD
CONFIGURE_OPTIONS=$3
INSTALL_DIR=$4
cd ${BUILD_DIR}
wget --continue ${SOURCE_URL}
if [ ! -e ${SOURCE_FOLDER} ] ; then
tar -xf ${SOURCE_ARCHIVE}
fi
cd ${SOURCE_FOLDER}
mkdir $BDIR
cd $BDIR
echo $PWD
echo ../configure ${CONFIGURE_OPTIONS} --prefix=${INSTALL_DIR}
../configure ${CONFIGURE_OPTIONS} --prefix=${INSTALL_DIR}
make uninstall | tee make.uninstall # clean up any previous installs...
make clean | tee make.clean
make | tee make.out
make check | tee make.check
make install | tee make.install
cat make.check | grep -i "fail\|Pass"
echo FINISHED
If you cut and paste this code into , $HOME/bin/download_and_install_from_source.sh. Then make sure its excutable $ chmod +x $HOME/bin/download_and_install_from_source.sh
add the following line to your .bashrc file, if its not there already.
export PATH=$HOME/bin:$PATH
logout and login again. Then you should see the following
$ 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.
GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating point numbers.
We could:
$ 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/usr/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 $HOME/usr/gcc_libs
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.
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 “ ” $HOME/usr/gcc_libs
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 " " $HOME/usr/gcc_libs
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" \ $HOME/usr/gcc_libs
make, takes 15 minutes make ckeck, takes 3 hours 15 minutes
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
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 " " $HOME/usr/gcc_libs
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 " " $HOME/usr/gcc_libs
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=/export/home/$USER/usr \ --with-gmp=$HOME/usr/gcc_libs --with-mpc=$HOME/usr/gcc_libs \ --with-mpfr=$HOME/usr/gcc_libs --with-ppl=$HOME/usr/gcc_libs \ --disable-cloog-version-check --enable-cloog-backend=isl --with-cloog=$HOME/usr/gcc_libs \ --enable-languages=c,c++,fortran,objc
The following languages will be built: c,c++,fortran,lto,objc
*** This configuration is not supported in the following subdirectories:
gnattools target-libada target-libgo target-libffi target-zlib
target-libjava target-boehm-gc
(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-D $ tail -f make.out
Expect the build to take about 1 hour 40 minutes.
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.
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-D $ tail -f make.check
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 85973 # of unexpected failures 39 # of unexpected successes 49 # of expected failures 264 # of unsupported tests 2173 === g++ Summary === # of expected passes 48668 # of unexpected failures 6 # of expected failures 286 # of unsupported tests 568 === gfortran Summary === # of expected passes 41004 # of expected failures 56 # of unsupported tests 66 === objc Summary === # of expected passes 2988 # of expected failures 6 # of unsupported tests 74 === libstdc++ Summary === # of expected passes 8851 # of expected failures 43 # of unsupported tests 146 === libmudflap Summary === # of expected passes 1905 # of unexpected failures 1 === libgomp Summary === # of expected passes 2998 === libitm Summary === # of expected passes 26 # of expected failures 3 # of unsupported tests 1
which is acceptable
testing took 3 hours 15 minutes to finish.
from inside the gcc 4.7.1 build directory
$ make install
remove the gcc 4.2.4 entries from your bashrc file and replace them with
# gcc 4.7.1 installed under $HOME/usr export PATH=$HOME/usr/bin:$PATH export LD_LIBRARY_PATH=$HOME/usr/lib64:$USR/lib:$HOME/usr/gcc_libs/lib:$LD_LIBRARY_PATH #add library flags, for future compliations export LDFLAGS="-L$HOME/usr/lib64 -L$HOME/usr/lib -L$HOME/usr/gcc_libs/lib" #add include folder for headers export CPPFLAGS="-I$HOME/usr/include -I$HOME/usr/gcc_libs/include" export F77=gfortran export FFLAGS=$CPPFLAGS # not a hundred percent certain if this one in necessary
log in and out again, and
$ gcc -v Target: x86_64-unknown-linux-gnu ... Thread model: posix gcc version 4.7.1 (GCC)
size of install
$ du -sh $HOME/usr 694M
clean up your build directory
$ rm -r /tmp/$USER/gcc_build