Application cmake => make install fails

I have installed HDF5 1.12.0 on Ubuntu 18.04 and created a minimal application, which I can compile with my CMakeLists.txt without trouble.

If I run from my (empty) build directory :
ccmake …/SourceConvert
respond to ccmakes inquiries with ©onfigure (e)xit (g)generate
make
./Converthdf ! Works just fine
make install ! Works just fine
~/bin/Converthdf
I receive error message :
==> Error message : ~/bin/Converthdf /home/reinhard/bin/Converthdf: error while loading shared iibraries: libhdf5_fortran.so.200: cannot open shared object file: No such file or directory
cp Converthdf ~/bin
~/bin/Converthdf ! works just fine

Apparently there is a difference between make install and the simple copy that I do not understand. Both binaries of Converthdf (the one in my build directory and the one after make install) have the same size
A diff says the binaries differ.

I had installed HDF5 with the script:
#!/bin/bash
rm -r $HOME/HDF_Group
tar -zxf CMake-hdf5-1.12.0.tar.gz
cd CMake-hdf5-1.12.0
cp …/HDF5options.cmake .
source ./build-unix.sh
cp -r build/_CPack_Packages/Linux/TGZ/HDF5-1.12.0-Linux/HDF_Group/ $HOME
cd $HOME/HDF_Group/HDF5/1.12.0/lib
rm -f libz.so*
ln -s /lib/x86_64-linux-gnu/libz.so.1 libz.so
ln -s /lib/x86_64-linux-gnu/libz.so.1.2.11 libz.so.1
ln -s /lib/x86_64-linux-gnu/libz.so.1.2.11 libz.so.1.2.11
ls -l
export HDF_DIR==/home/reinhard/HDF_Group/HDF5/1.12.0/share/cmake/hdf5/
cd ~

The replacement of the libz seemed to be necessary as I got compilation errors with the HDF5 libz.

My CMakeLists.txt file is:

cmake_minimum_required (VERSION 3.10.2)
project (Convert C CXX Fortran)
set (FIND_HDF_COMPONENTS C CXX Fortran shared)
find_package (HDF5 NAMES "hdf5" COMPONENTS ${FIND_HDF_COMPONENTS})
if (HDF5_FOUND)
  if (HDF5_shared_C_FOUND)
    set (LINK_LIBS ${LINK_LIBS} ${HDF5_C_SHARED_LIBRARY})
  endif ()
  if (HDF5_shared_CXX_FOUND)
  set (LINK_LIBS ${LINK_LIBS} ${HDF5_CXX_SHARED_LIBRARY})
  endif ()
    if (HDF5_shared_Fortran_FOUND)
     set (LINK_LIBS ${LINK_LIBS} ${HDF5_FORTRAN_SHARED_LIBRARY})
     INCLUDE_DIRECTORIES (${HDF5_INCLUDE_DIR_FORTRAN})
   endif ()
else ()
   message (FATAL_ERROR " HDF5 is Required")
endif ()
message ( STATUS " LINK_LIBS ${LINK_LIBS}" )
INCLUDE_DIRECTORIES (${HDF5_INCLUDE_DIR})
add_executable (Converthdf ConvertHDF.f90)
target_link_libraries (Converthdf ${LINK_LIBS})
install (TARGETS Converthdf DESTINATION bin)

The F90 application is:

program convertHDF
use HDF5
implicit none
integer :: hdferr
logical :: hdf_data
character(128) :: data_file
INTEGER(HID_T) :: file, space, dset
INTEGER(HSIZE_T), DIMENSION(1:3)  :: dims
REAL, DIMENSION(:,:,:), ALLOCATABLE, TARGET :: data_read
TYPE(C_PTR) :: f_ptr
integer :: jdim = 41
CALL h5open_f(hdferr)
data_file = 'meanfield.h5'
call execute_command_line('rm -f '//data_file, wait=.true.)
CALL h5fcreate_f(data_file, H5F_ACC_TRUNC_f, file, hdferr)
dims = (/jdim,jdim,jdim/)
allocate(data_read(1:dims(1),1:dims(2),1:dims(3)))
data_read = 1.0
CALL h5screate_simple_f(3, dims, space, hdferr)
CALL h5dcreate_f(file, 'data', H5T_NATIVE_REAL, space, dset, hdferr)
f_ptr = C_LOC(data_read(1,1,1))
CALL h5dwrite_f(dset, H5T_NATIVE_REAL, f_ptr, hdferr)
CALL h5dclose_f(dset , hdferr)
CALL h5sclose_f(space, hdferr)
CALL h5fclose_f(file , hdferr)
end program convertHDF

Can you please upload your minimal application to github, or attach the tarball to your post?

Steven, as I am a new user to the HDF forum, the form did not let me add an attachement. Might I ask which github repository you are referring to?

Hello Reinhard,

you could send a PR to https://github.com/steven-varga/HDFGroup-mailinglist, placeing your compilable example in a sub directory. This is only an alternative to any public place where others can find, download and compile your example. For instance you could create a public repository on github then upload your material.

I just noticed that your code is in Fortran, and I am mostly interested an C++ or C problems – my bad! Nevertheless it is good idea to upload it to a public place so people can quickly look – and won’t get bogged down in details such as writing plumbing code / harness for a snippet.

best: steve

Hello Steven,
My apologies, I should have created the github repository right away. Its now available at

I added a C-Example as well, and do get the identical effect. As the CMakeLists.txt is identical in both cases I am afraid that there is something fishy in this file. I have never encountered this effect in other projects though.
Best Reinhard

Hello Steven, my apologies, I should have made a github repository right away. I did this, at:

The README.md summarizes the issue at hand again.
I have added an example in C, for ease I just took the example from the HDF5 group at Examples by API: Read/write integer dataset
Interestingly I get the identical issue as in my original post; the binaries after make install fail with libraries that they do not find.

Hi Reinhard,
I’ve received your private message, and replied to it; less certain if you got it – seeing this post with the time stamp.

In any event, can you please try this: https://github.com/steven-varga/HDF5_CMAKE/tree/master/SourceCexample, let me know if worked…

I do this somewhat differently, take a look at the cmake files of H5CPP examples: https://github.com/steven-varga/h5cpp/blob/master/examples/CMakeLists.txt

Also I do recommend you to check out H5CPP, here is my five minute presentation on it – in this case you will not need C++ and high level libraries.
Basically you can rely on the C API, and instead of package config just include the FindHDF5 module, will do the job for you; picking the shared or static version on host system depending on availability.

I can’t look at the fortran example today, but as time allows will check it out.
best: steve

Hi Steven,

  yes I did receive your mail, I have been traveling today and will check it out later today.

  The time stamp of my posting is due to the moderator at HDF forum. I had placed my first response some 18 hours ago,and repeated it this morning (European time) as I thought it was lost ...

  Thanks for the help I'll keep you posted how that works for my main project which is a big Fortran project

Best

Reinhard

Hi Reinhard,

I didn’t quite forget about you: So last night I looked at your Fortran case, the first gotcha was that HDF5 Fortran modules don’t get installed by default; so I recompiled my HDF5 with Fortran. So far good, then I noticed that the xyx.pc package config file didn’t get installed, which your script uses implicitly – sort of a bummer, will have to revisit that approach – on the other hand I did try cmake module approach: FindHDF5, and could not make it work with Fortran:

Fatal Error: Can't open module file ‘hdf5.mod’ for reading at (1): No such file or directory

For some reasons the HDF5 module path is not picked up properly. If anyone reading this happened to know how to set the cmake module path for Fortran? or confirm that is the INCLUDE_DIRECTORIES ? (i manually checked and the module files got installed in /usr/local/include)

On the bright side, I got success calling h5fc the HDF5 Fortran compiler script directly on the example! From this cmake page is this ${HDF5_Fortran_COMPILER_EXECUTABLE}; maybe you could just use it?

steve