Compiling old OpenFOAM

This page is for compiling OpenFOAM 2.3.0 on Ubunutu 24.

It should be helpful for understanding how to compile similar versions of OpenFOAM on other Linux systems, so long as they are similar ages. OpenFOAM 2.3.0 was released in February 2014, and Ubuntu 24 was released March 2026.

Preparation

Download OpenFOAM-2.3.0

mkdir -p ~/OpenFOAM
cd ~/OpenFOAM
tar -xf ~/Downloads/OpenFOAM-2.3.0.tgz
tar -xf ~/Downloads/ThirdParty-2.3.0.tgz

First extract these in the standard location, i.e. into ~/OpenFOAM/. If everything is right, you'll have files called ~/OpenFOAM/OpenFOAM-2.3.0/Allwmake and ~/OpenFOAM/ThirdParty-2.3.0/Allwmake.

It is not worth the effort bringing the code up to modern standards so it can be compiled with a modern compiler. Instead, we'll compile gcc 4.8, which is a similar age to this version of OpenFOAM. However, gcc 4.8 is also too old to compile on a modern system, and needs patches to make it work.

We'll be using the makeGcc48 script in the ThirdParty-2.3.0 directory. This requires the following additional downloads:

Extract these into ~/OpenFOAM/ThirdParty-2.3.0 so that you have ThirdParty-2.3.0/gcc-4.8.2, ThirdParty-2.3.0/gmp-5.1.2, ThirdParty-2.3.0/mpc-1.0.1, and ThirdParty-2.3.0/mpc-1.3.1.

Download the following patches, which we'll use later.

Create ~/OpenFOAM/OpenFOAM-2.3.0/etc/prefs.sh with the following contents:

foamCompiler=ThirdParty
WM_COMPILER=Gcc48
WM_MPLIB=OPENMPI
WM_NCOMPPROCS=10

The last line, WM_NCOMPPROCS, configures parallel builds. Adjust it according to your build environment. Do not set this to a higher number than the number of cores the computer has. You can find the number of cores available by running:

getconf _NPROCESSORS_ONLN

Source the OpenFOAM environment

Run this command to set the environment variables used by OpenFOAM and wmake. Ignore the message about the missing gcc-4.8.2 installation - it says that because we haven't built it yet.

.  ~/OpenFOAM/OpenFOAM-2.3.0/etc/bashrc

Installing old GCC

Before compiling gcc, apply the patch, which fixes struct ucontext and struct __res_state.

cd ~/OpenFOAM/ThirdParty2.3.0
patch -p0 <~/Downloads/gcc-4.8.2-ubuntu24.patch

The gcc compilation process involes building the compiler using the system compiler, and then building the compiler again with itself, and then the same again to confirm that the build produces the same result. When it does the second and third parts, it will use the libstdc++ that it just compiled. libsdc++ is needed by msgfmt, but the one just made is too old, breaking the compilation process. We need to disable LD_LIBRARY_PATH while it runs msgfmt.

Create a file, ~/OpenFOAM/ThirdParty-2.3.0/foo/msgfmt with the following contents:

#!/bin/sh
LD_LIBRARY_PATH=
exec /usr/bin/msgfmt "$@"

Make it executable:

chmod +x ~/OpenFOAM/ThirdParty-2.3.0/foo/msgfmt

Run the gcc compilation, with this directory added to the PATH: (This line is one command.)

PATH=$HOME/OpenFOAM/ThirdParty-2.3.0/foo:$PATH  ./makeGcc48

Removing downgraded shared libraries

Now comes the messy bit. The libraries just installed in ~/OpenFOAM/ThirdParty-2.3.0/platforms/, and present on the library path, are older than the system libraries. Because OpenFOAM uses LD_LIBRARY_PATH to add these libraries, they override the better choices from /lib/x86_64-linux-gnu/. (If not on Ubunutu 24, your libraries may be in /lib64 or /usr/lib64 or /usr/lib/x86_64-linux-gnu.)

For each library, there is a major and minor version. Major version changes happen when there is an ABI-incompatible change. Within a series, libraries with a higher minor version should be compatible, so it is safe to remove the libraries that are the same major version and lower minor version than the corresponding system library. We want to do that because having libraries with a lower minor version breaks system programs, including editors and graphics drivers, which you'll want to use with OpenFOAM.

The libstdc++ just installed has filename libstdc++.so.6.0.18, which corresponds to version 6.0.18. The major version is 6, so we can think of this library as being named "libstdc++.so.6".

Generally speaking, the major version is just the first digit. Officially, it is based on the soname, which you can read like this:

find ~/OpenFOAM/ThirdParty-2.3.0/platforms -type f |
          grep '\.so\.[0-9\.]*' | xargs objdump -p | grep SONAME

  SONAME               libquadmath.so.0
  SONAME               libtsan.so.0
  SONAME               libstdc++.so.6
  SONAME               libmudflapth.so.0
  SONAME               libitm.so.1
  SONAME               libgcc_s.so.1
  SONAME               libmudflap.so.0
  SONAME               libgomp.so.1
  SONAME               libssp.so.0
  SONAME               libasan.so.0
  SONAME               libatomic.so.1
  SONAME               libgmp.so.10
  SONAME               libgmpxx.so.4
  SONAME               liblto_plugin.so.0
  SONAME               libmpc.so.3
  SONAME               libmpfr.so.4

To see which of these are already installed in the system, we can look for the corresponding name in /lib/x86_64-linux-gnu:

(cd /lib/x86_64-linux-gnu/ && ls -l `find ~/OpenFOAM/ThirdParty-2.3.0/platforms -type f |
         grep '\.so\.[0-9\.]*' | xargs objdump -p | grep SONAME | sed 's/.* //'`)

ls: cannot access 'liblto_plugin.so.0': No such file or directory
ls: cannot access 'libmudflapth.so.0': No such file or directory
ls: cannot access 'libmudflap.so.0': No such file or directory
ls: cannot access 'libssp.so.0': No such file or directory
ls: cannot access 'libasan.so.0': No such file or directory
ls: cannot access 'libmpfr.so.4': No such file or directory
lrwxrwxrwx 1 root root     18 Dec 18 21:36 libatomic.so.1 -> libatomic.so.1.2.0
-rw-r--r-- 1 root root 183024 Dec 18 21:36 libgcc_s.so.1
lrwxrwxrwx 1 root root     16 Dec 18 21:36 libgomp.so.1 -> libgomp.so.1.0.0
lrwxrwxrwx 1 root root     15 Dec 18 21:36 libitm.so.1 -> libitm.so.1.0.0
lrwxrwxrwx 1 root root     20 Dec 18 21:36 libquadmath.so.0 -> libquadmath.so.0.0.0
lrwxrwxrwx 1 root root     19 Dec 18 21:36 libstdc++.so.6 -> libstdc++.so.6.0.33
lrwxrwxrwx 1 root root     16 Dec 18 07:26 libtsan.so.0 -> libtsan.so.0.0.0
lrwxrwxrwx 1 root root     16 Oct  2  2024 libgmp.so.10 -> libgmp.so.10.5.0
lrwxrwxrwx 1 root root     17 Oct  2  2024 libgmpxx.so.4 -> libgmpxx.so.4.7.0
lrwxrwxrwx 1 root root     15 Oct  2  2024 libmpc.so.3 -> libmpc.so.3.3.1

You should do this yourself - your system may have different libraries installed. The errors, highlighted here in red, are good – that means that there is no clash of library versions. The libraries that are found are potential problems.

Because the systems are so different in age, there is no need to actually compare the version numbers; you can assume that the system version is newer. We'll do that command again, but this time, take the base of the filename, without the '.so', and look that up in the OpenFOAM library directory. These are the files that we want to delete.

(cd /lib/x86_64-linux-gnu/ && ls `find ~/OpenFOAM/ThirdParty-2.3.0/platforms -type f | grep '\.so\.[0-9\.]*' |
      xargs objdump -p | grep SONAME | sed 's/.* //'` 2>/dev/null) |
    sed 's/\.so\..*/\*/' | xargs -ifoo find ~/OpenFOAM/ThirdParty-2.3.0/platforms -name foo

/home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/gcc-4.8.2/lib64/libatomic.la
/home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/gcc-4.8.2/lib64/libatomic.so
/home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/gcc-4.8.2/lib64/libatomic.a
/home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/gcc-4.8.2/lib64/libatomic.so.1
/home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/gcc-4.8.2/lib64/libatomic.so.1.0.0
/home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/gcc-4.8.2/lib64/libgcc_s.so.1
/home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/gcc-4.8.2/lib64/libgcc_s.so
/home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/gcc-4.8.2/lib64/libgomp.so
/home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/gcc-4.8.2/lib64/libgomp.spec
[Click to expand...]
/home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/mpc-1.0.1/lib/libmpc.so /home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/mpc-1.0.1/lib/libmpc.so.3.0.0 /home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/mpc-1.0.1/lib/libmpc.a /home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/mpc-1.0.1/lib/libmpc.so.3 /home/your_username/OpenFOAM/ThirdParty-2.3.0/platforms/linux64/mpc-1.0.1/lib/libmpc.la

Look through your list. If it looks similar to the above, then do the same check, but actually delete the files this time.

(cd /lib/x86_64-linux-gnu/ && ls `find ~/OpenFOAM/ThirdParty-2.3.0/platforms -type f | grep '\.so\.[0-9\.]*' |
      xargs objdump -p | grep SONAME | sed 's/.* //'` 2>/dev/null) |
    sed 's/\.so\..*/\*/' | xargs -ifoo find ~/OpenFOAM/ThirdParty-2.3.0/platforms -name foo -delete

If you look in the platforms directories, such as ThirdParty-2.3.0/platforms/linux64/gcc-4.8.2/lib64/, it will be smaller. We've removed anything that clashes with a system library, but left everything else alone.

Compiling OpenFOAM

Now we need to patch up OpenFOAM itself. There are two issues - an overly broad, and incorrect, test for the version of flex, and the optional setNaN allocator that uses a deleted feature of glibc. The flex test is fixed by making it more specific. The setNaN allocator initialises newly requested memory to NaNs and is used for debugging OpenFOAM itself; it is activated by the environment variable, FOAM_SETNAN, and is not needed for normal operation. It is "fixed" by deleting it.

cd ~/OpenFOAM/OpenFOAM-2.3.0
patch -p1 <~/Downloads/openfoam-2.3.0-ubuntu24.patch

Now compile OpenFOAM

./Allwmake

Peter Benie <peterb@chiark.greenend.org.uk>
Linux