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