Installing HDF5 and netCDF from source

The main steps to compile and install parallel HDF5 and netCDF, both with Fortran support. This post is an attempt to properly document the installation of both libraires and is an extension of the previous post about h5py.

Please note we will install everything in /usr/local.

Building parallel HDF5 1.8.13 from source for Fortran

After getting the sources, configure HDF5

$ CC=mpicc CFLAGS=-fPIC ./configure --prefix=/usr/local --enable-fortran 

If you want to use h5py later on (as explained in this post), I recommend to use the following:

$ ./configure --enable-fortran --enable-parallel --prefix=/usr/local --enable-shared 
$ make

Then compile and install:

$ make
$ make install

Building NetCDF 4.3.2 with HDF5 support

Get the latest C-version on github if you do not want to have an “undefined reference to H5Pset_fapl_mpiposix”. At the time of this writing, the version was 4.3.3-rc1. Then install it with:

$ CC=mpicc CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib ./configure --prefix=/usr/local
$ make
$ make install

Then get the Fortran version of netCDF (they are now separated). I used the 4.4.0. Set the installation with:

$ export LD_LIBRARY_PATH=/usr/local/lib
$ ./configure --prefix=/usr/local

Do not forget to export LD_LIBRARY_PATH somewhere in your .bashrc too.