HDF5 CMake build

We strongly recommend using CMake to build HDF5. CMake is required to build HDF5 on Windows. HDF Group continues to work to improve HDF5 CMake scripts, but here are a couple bugs present at least through HDF5 1.12.0 and 1.10.7:

  • cmake -S hdf5 -B hdf5/build flags don’t work properly–the CMake build will fail partway through with weird platform-dependent errors. Instead you need to use old-fashioned mkdir hdf5/build; cd hdf5/build; cmake ..
  • HDF5 builds test executables that don’t pickup CMake environment variables. You must set compiler variables CC and FC in the shell. This is particularly true when using non-system-default compilers.

These CMake options build HDF5 for Fortran as fast as possible by omitting optional items. If these seems too complicated, try our one-step Python build HDF5 script.

mkdir hdf5/build
cd hdf5/build


cmake --build .

This creates static and dynamic HDF5 libraries under the user install prefix–we don’t show the library suffixes for simplicity. Note: the *stub files may not be present.


The Fortran .mod files that need to be included are under


Tell CMake to use this HDF5 from your project by:

cmake -B build -DHDF5_ROOT=~/.local/hdf5