I have already installed HDF5 under Ubuntu :
sudo apt install libhdf5-dev
I have a Qt program using HDF5 that compiles fine under CentOS 7 but not under Ubuntu :
erreur : hdf5.h: No such file or directory #include
^~~~~~~~
I am using CMake to generate the build files and in it, I didn't need to handle HDF5 for the CentOS build.
I added this part that I found on the web to the CMake script but I still have a compile error.
FIND_PACKAGE(ZLIB)
FIND_LIBRARY(HDF5_LIBRARY hdf5 ...)
FIND_LIBRARY(HDF5_HL_LIBRARY hdf5_hl ...)
IF(NOT TARGET hdf5 AND NOT TARGET hdf5_hl)
ADD_LIBRARY(hdf5 SHARED IMPORTED)
ADD_LIBRARY(hdf5_hl SHARED IMPORTED)
ENDIF()
SET_TARGET_PROPERTIES(hdf5 PROPERTIES IMPORTED_LOCATION ${HDF5_LIBRARY})
SET_TARGET_PROPERTIES(hdf5_hl PROPERTIES IMPORTED_LOCATION
${HDF5_HL_LIBRARY})
SET(HDF5_LIBRARIES hdf5 hdf5_hl ${ZLIB_LIBRARIES} m)
What can I add to the script to fix the include problem ?
with "locate", I found different hdf5.h :
/usr/include/hdf5/mpich/hdf5.h
/usr/include/hdf5/openmpi/hdf5.h
/usr/include/hdf5/serial/hdf5.h
I really want to know what "libhdf5-dev" refers to ? and why HDF5 is not provided correctly under Ubuntu (it's crazy !)
解决方案
Under Ubuntu, I was forced to add MPI to the CMake script. I don't like this solution but its CMake and Ubuntu fault...
find_package(HDF5)
find_package(MPI)
....
target_link_libraries(${binary} ${MPI_LIBRARIES} ${HDF5_LIBRARIES} ... )
target_include_directories(${binary} PRIVATE ${HDF5_INCLUDE_DIRS})