I am getting the following error when running make
in my build directory
/usr/bin/ld: cannot find -lhdf5_hl
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-g++' failed with exit status 1
I have libhdf5-dev installed and and libhdf5_hl.so exists in my directory /usr/lib/x86_64-linux-gnu/hdf5/serial. However, when I run cmake ..
in the build directory, I get this line which doesn't include libhdf5_hl.so:
-- Found HDF5: /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libm.so;/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5_cpp.so;/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libm.so (found version "1.10.4") found components: C CXX HL
This is the CMakeList.txt that I am using:
cmake_minimum_required(VERSION 3.10)
# set the project name and version
project(HDDM VERSION 1.0)
include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_VERSION_MAJOR "${HDDM_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${HDDM_VERSION_MINOR}")
include(CPack)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# look for installed packages in local build area
list(APPEND CMAKE_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/share/cmake)
# check for presence of compression libraries
find_package(BZip2 REQUIRED)
find_package(ZLIB REQUIRED)
# Xerces-C support
if(DEFINED XERCESCROOT)
message("Looking in ${XERCESCROOT} for local Xerces-C installation")
find_package(XercesC PATHS ${XERCESCROOT} NO_DEFAULT_PATH REQUIRED)
endif()
find_package(XercesC REQUIRED)
# ROOT support
if(DEFINED ROOTSYS)
message("Looking in ${ROOTSYS} for local ROOT installation")
find_package(ROOT PATHS ${ROOTSYS} REQUIRED NO_DEFAULT_PATH)
endif()
find_package(ROOT QUIET)
# HDF5 support
set(CMAKE_IGNORE_PATH
$ENV{CONDA_PREFIX}/bin $ENV{CONDA_PREFIX}/lib $ENV{CONDA_PREFIX}/include
)
if(DEFINED HDF5_ROOT)
message("Looking in ${HDF5_ROOT} for local HDF5 installation")
find_package(HDF5 REQUIRED COMPONENTS C CXX HL PATHS ${HDF5_ROOT} NO_DEFAULT_PATH)
elseif(EXISTS "${CMAKE_INSTALL_PREFIX}/share/cmake/hdf5-config.cmake")
message("Looking in ${CMAKE_INSTALL_PREFIX} for local HDF5 installation")
set(HDF5_DIR "${CMAKE_INSTALL_PREFIX}/share/cmake")
find_package(HDF5 REQUIRED COMPONENTS C CXX HL PATHS ${HDF5_DIR} NO_DEFAULT_PATH)
if(NOT DEFINED HDF5_INCLUDE_DIRS)
set(HDF5_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include")
endif()
set(CMAKE_LIBRARY_PATH "${CMAKE_INSTALL_PREFIX}/lib64" "${CMAKE_INSTALL_PATH}/lib")
find_library(HDF5_LIBRARIES hdf5)
find_library(HDF5_HL_LIBRARIES hdf5_hl)
else()
find_package(HDF5 REQUIRED COMPONENTS C CXX HL)
endif()
# xalan-j2 package
if(NOT DEFINED XALANJ2_PATH)
set(XALANJ2_PATH /usr/share/java)
endif()
if(EXISTS ${XALANJ2_PATH}/xalan2.jar)
message("-- Found xalan2 at ${XALANJ2_PATH}/xalan2.jar")
elseif(EXISTS ${XALANJ2_PATH}/xalan-j2.jar AND EXISTS ${XALANJ2_PATH}/xalan-j2-serializer.jar)
message("-- Found xalan-j2 at ${XALANJ2_PATH}/xalan-j2.jar")
else()
message("Cannot find xalan-j2 at ${XALANJ2_PATH}/xalan-j2.jar, some schema utilities will fail!")
endif()
# xmllint command
if(NOT DEFINED XMLLINT_PATH)
set(XMLLINT_PATH /usr/bin)
endif()
if(EXISTS ${XMLLINT_PATH}/xmllint)
message("-- Found xmllint at ${XMLLINT_PATH}/xmllint")
else()
message("Cannot find xmllint at ${XMLLINT_PATH}/xmllint, some schema utilities will fail!")
endif()
# libtirpc
include_directories(${CMAKE_SOURCE_DIR}/src/tirpc)
install(FILES ${CMAKE_SOURCE_DIR}/src/unistd_win32.h DESTINATION include)
# add the xstream library
add_subdirectory(xstream)
# build the executables
add_subdirectory(src)
# install the scripts
add_subdirectory(scripts)
# install the schemas
add_subdirectory(schemas)
# install the examples
add_subdirectory(models)
add_subdirectory(examples)
# define a separate target for the example python modules
add_custom_target(modules_install ALL
COMMAND ${CMAKE_SOURCE_DIR}/scripts/python_module_installer.sh
${CMAKE_BINARY_DIR}/models
${CMAKE_INSTALL_PREFIX}
DEPENDS python_modules
)
# package config
set(INCLUDE_INSTALL_DIR include/)
set(LIB_INSTALL_DIR lib/)
set(SYSCONFIG_INSTALL_DIR etc/hddm/)
#...
include(CMakePackageConfigHelpers)
configure_package_config_file(HddmConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/HddmConfig.cmake
INSTALL_DESTINATION ${LIB_INSTALL_DIR}/hddm/cmake
PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/HddmConfigVersion.cmake
VERSION 1.0.0
COMPATIBILITY SameMajorVersion )
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/HddmConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/HddmConfigVersion.cmake
DESTINATION ${LIB_INSTALL_DIR}/hddm/cmake )
The variable HDF5_LIBRARIES
contains list of "normal" libraries for HDF5 bindings. Libraries for high level (HL) API are listed in the variable HDF5_HL_LIBRARIES
. This is noted in the documentation for module FindHDF5.cmake
(which is executed during find_package(HDF5)
):
HDF5_LIBRARIES
Required libraries for all requested bindings
HDF5_HL_LIBRARIES
Required libraries for the HDF5 high level API for all bindings, if the HL component is enabled