Big-Bytes decided to write up a quick tutorial on how to install OpenFOAM 2 in the user space. Administrators and users constantly battle with dependencies especially with the latest software releases. This problem begins when a system administrator installs and configures a Linux system. All is well in the beginning and users are happy but at some point the user will begin to complain about outdated software dependency versions. Some system dependencies can be upgraded rather quickly but others not and a user space compile is imminent. This was in the case of GCC, its linkers and the dependencies required to build GCC.
OpenFoam 2 requires GCC 4.4 and above to compile correctly and on a Scientific Linux 5.4 system only GCC 4.1.2 was available. It is not recommended to upgrade a system-wide compiler such as GCC and its also not trivial to upgrade a linux machine while having to deal with the demands of users.
Compile GCC
Create a directory $HOME/contrib and $HOME/contrib/build. You can of course name these directories anyway you like.
Download all the dependencies for GCC. These are listed below and extract into contrib.
- GMP - http://gmplib.org
- MPFR - http://www.mpfr.org
- MPC - http://www.multiprecision.org
- Binutils - http://www.gnu.org/software/binutils
- Extract with tar xfvz gmp.tar.gz
- Change into the directory and compile with ./configure --prefix=$HOME/contrib/gmp-complete
- make && make install
- Extract with tar xfvz mpfr.tar.gz
- Change into the directory and compile with ./configure --prefix=$HOME/contrib/mpfr-complete --with-gmp-build=<directory in which the source is in, the extracted directory and not the compiled directory>
- make && make install
- Extract with tar xfvz mpc.tar.gz
- Change into the directory and compile with ./configure --prefix=$HOME/contrib/mpc-complete --with-gmp=$HOME/contrib/gmp-complete --with-mpfr=$HOME/contrib/mpfr-complete
- make && make install
- Extract with bunzip binutils && tar xfv binutils.tar
- Change into the directory and compile with ./configure --prefix=$HOME/contrib/binutils-complete
- make && make install
- make target_header_dir=$HOME/binutils-complete/include -C libiberty
- Download the latest version of GCC from a mirror site into $HOME/contrib and extract there.
- Change directory into the $HOME/contrib/build. Notice that we are NOT executing the "./configure" script from within the extracted directory but rather from a build directory. Its extremely important to adhere to this rule.
- cd $HOME/contrib/build
- ../gcc-4.6.1/configure --prefix=$HOME/contrib/gcc-complete/ --enable-languages=c,c++ --with-gmp=$HOME/contrib/gmp-complete --with-mpc=$HOME/contrib/mpc-complete/ --with-mpfr=$HOME/contrib/mpfr-complete/ ( NB: notice the importance of the two periods before the configure script )
- make -j 4 ( This assumes that you would like the compile of GCC to consume 4 CPU processors.
- make install
- make clean ( This will erase all the intermediate files )
- $HOME/contrib/gcc-complete/bin/gcc –version should give show the correct version.
- Create directory $HOME/OpenFOAM
- Download the OpenFOAM2 and ThirdParty compression files from the OpenFOAM website
- Extract both into the $HOME/OpenFOAM directory with the " tar xfvz <filename>" command
- Change directory into $HOME/OpenFOAM/OpenFOAM-2.0.1/etc
- Open up the " bashrc " file and locate the " foamInstall=$HOME " variable. If you are installing OpenFOAM into a alternate location you may update the location here.
- Save the file and exit
- Add the following to $HOME/.bashrc - "source $HOME/OpenFOAM/OpenFOAM-2.0.1/etc/bashrc"
- Set the following environment variable to get OpenFOAM to utilize the maximum number of CPU processors on the system. " export WM_NCOMPPROCS=4 "
- Change directory into $HOME/OpenFOAM/ThirdParty-2.0.1/
- Execute the file " ./Allwmake "
- When completed successfully execute "./$HOME/OpenFOAM/OpenFOAM-2.0.1/etc/bashrc". This will refresh the shell environment.
- Change directory into $HOME/OpenFOAM/OpenFOAM-2.0.1/ and execute " ./Allwmake "