So I have a small Fortran library that provides some wrappers for HDF5 Fortran calls. I also have a small test that calls the interfaces defined in the library. I know that the issue is with the way I'm linking HDF5. I've checked my build of HDF5 (specifically 1.8.15-patch1), ensured that it was all installed correctly to my machine, and that there were no alternate builds on my machine. I am building both projects with the compilers set as gcc-5, g++-5, and gfortran-5.
I am using CMake 3.2.2 to generate makefiles.
The layout of the project is something like this:
CMakeLists.txt
test
|_____ CMakeLists.txt
|_____ dump_test.f90
src
|_____ data
|_____ CMakeLists.txt
|_____ dump_data.f90
|_____ <other libraries>
In the main CMakeLists.txt, I have
project(testlibs)
ENABLE_LANGUAGE(Fortran)
SET(HDF5_USE_STATIC_LIBRARIES ON)
find_package(HDF5 COMPONENTS C CXX Fortran REQUIRED)
SET(CMAKE_Fortran_FLAGS_DEBUG "-g -O0 -DDEBUG")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/src/data)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tests)
In the data library CMakeLists.txt, I have
include_directories(${HDF5_INCLUDE_DIRS})
add_library(dumpData STATIC ${CMAKE_CURRENT_LIST_DIR}/dump_data.f90)
target_link_libraries(dumpData hdf5 hdf5_fortran )
install(TARGETS dumpData DESTINATION ${CMAKE_INSTALL_RPATH})
In the test CMakeLists.txt, I have
include_directories(${HDF5_INCLUDE_DIRS})
include_directories("${PROJECT_BINARY_DIR}/src/data")
add_executable(dumptest EXCLUDE_FROM_ALL dump_test.f90)
target_link_libraries(dumptest dumpData)
I've seen suggestions that say to link the library against dl also, but that doesn't seem to affect anything.
I get no errors when I build the library but when I build the example, I get a bunch of undefined references
//usr/local/lib/libhdf5_fortran.a(H5_ff.f90.o): In function `__h5lib_MOD_h5dont_atexit_f':
H5_ff.f90:(.text+0xed): undefined reference to `h5dont_atexit_c_'
//usr/local/lib/libhdf5_fortran.a(H5_ff.f90.o): In function `__h5lib_MOD_h5garbage_collect_f':
H5_ff.f90:(.text+0x109): undefined reference to `h5garbage_collect_c_'
//usr/local/lib/libhdf5_fortran.a(H5_ff.f90.o): In function `__h5lib_MOD_h5check_version_f':
H5_ff.f90:(.text+0x143): undefined reference to `h5check_version_c_'
//usr/local/lib/libhdf5_fortran.a(H5_ff.f90.o): In function `__h5lib_MOD_h5get_libversion_f':
H5_ff.f90:(.text+0x17d): undefined reference to `h5get_libversion_c_'
//usr/local/lib/libhdf5_fortran.a(H5_ff.f90.o): In function `__h5lib_MOD_h5close_f':
H5_ff.f90:(.text+0x1cc): undefined reference to `h5close_types_c_'
//usr/local/lib/libhdf5_fortran.a(H5_ff.f90.o): In function `__h5lib_MOD_h5open_f':
H5_ff.f90:(.text+0x20a): undefined reference to `h5init_types_c_'
H5_ff.f90:(.text+0x2ba): undefined reference to `h5init_flags_c_'
H5_ff.f90:(.text+0x2d0): undefined reference to `h5init1_flags_c_'
Am I missing something in my CMake files? I'm getting that its a issue of the HDF5 Fortran functions not being able to find the underlying C functions.
hdfandhdf5_fortranlibraries. I'm pretty certain thathdf5_fortranshould be first/usr/bin/h5fc -noshlib ...and see what the differences are.