Building exodusII

I have spent over a week trying to get exodusII libraries to build on a Linux machine, and now I have finally achieved it. There have been many attempts that I have failed on, and I hope by documenting my process, it will help other people who may one day run into a similar issue.

Firstly, Exodus has many dependencies, most of which are probably installed already on a standard working installation. Two dependencies that are probably not already installed that are required are netcdf & hdf5. In this post, I will outline how to install hdf5, netcdf and ultimately ExodusII.

Do not use yum to get these packages and expect them to work… they don’t. I would recommend that you use yum to download these packages just so the yum database recognises these packages as being installed.

To download them, use the following command:

sudo yum install hdf5 hdf5-devel hdf5-static netcdf netcdf-devel netcdf-static

Once the non-working copies have been installed, we will write over the top of them by building the packages from source. First download the packages from the following locations:
hdf5: http://www.hdfgroup.org/HDF5/release/obtainsrc.html
netcdf: http://www.unidata.ucar.edu/downloads/netcdf/index.jsp
exodus: https://sourceforge.net/projects/exodusii/

Building hdf5

As netcdf depends on hdf5, the first step needed is to compile and install hdf5. After downloading the source from the above link, extract the package using tar (tar -xvf hdf5-1.8.13.tar.gz). Change into that directory and issue the following command to configure the build (all on one line):

cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_C_FLAGS=”-fPIC” -DHDF5_BUILD_HL_LIB=ON -DHDF5_BUILD_FORTRAN=ON -DCMAKE_INSTALL_PREFIX=/usr/local ./

Follow this by building the project with the command ” make “, and finally install the project using the command ” make install “.

Building netcdf

Once hdf5 has been successfully built and installed, it is time to build and install netcdf. The process is similar to that of building hdf5; firstly the package is extracted by running ” tar -xvf netcdf-4.3.2.tar.gz “. Change into the netcdf-4.3.2 directory and issue the following command all on one line to configure the project:

cmake -DHDF5_LIBRARIES=”/usr/local/lib/libhdf5.a;/usr/local/lib/libhdf5_hl.a” -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_C_FLAGS=”-fPIC -ldl -lhdf5_hl -Wl,–start-group -lhdf5″ -DCMAKE_INSTALL_PREFIX=/usr/local ./

(Note there is no whitespace between -Wl, and –start-group

Once the project is configured, build it using ” make “, and finally install it using ” sudo make install “.

Building exodusII

Finally, exodusII can be installed. Again, untar the package ” tar -xvf exodus-6.09.tar.gz “, change into the directory, and run the following cmake command:

cmake -DCMAKE_Fortran_COMPILER=`which gfortran` -DBUILD_SHARED=OFF -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_C_FLAGS=”-fPIC -ldl -lhdf5_hl -Wl,–start-group -lhdf5″ -DCMAKE_CXX_FLAGS=”-fPIC -ldl -lhdf5_hl -Wl,–start-group -lhdf5″ -DCMAKE_Fortran_FLAGS=”-fPIC -ldl -lhdf5_hl -Wl,–start-group -lhdf5″ -DCMAKE_INSTALL_PREFIX=/usr/local -DPYTHON_INSTALL=/usr/local/python ./

I have no doubt that there is a much more visually appealing way of compiling exodusII and the above packages, but I can attest to this method working, despite its apparent ugliness. Also, you could put the python wrapper in the site-packages directory if you wanted (-DPYTHON_INSTALL=/usr/local/python). Up to individual taste. Finally, I prefer to build these “specialist” libraries statically, and link the standard libraries (math, glibc etc. etc.) dynamically so that the final binary is easier distributed. Obviously there are some detriments to this approach, so if you prefer shared libraries, just modify the relevant CMake tags.

Linking the Library

Once the libraries are all installed, you can now compile projects using the libraries. To compile a program to use the the exodus functions, the full command to compile test1.c with linker directives is:

gcc test1.c -lexodus -lnetcdf -lhdf5_hl -lhdf5 -lcurl -ldl -lm -lc

One comment on “Building exodusII
  1. […] Building exodusII […]

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: