在Linux环境中使用cmake安装时HDF5的未定义符号

时间:2018-10-23 15:23:33

标签: cmake linker static-libraries hdf5

我已经能够使用CMake(使用HDF5)安装和启动程序,但是一旦我访问了该程序的“关于”下拉链接,它就会崩溃并出现以下错误:

python: symbol lookup error: /nobackup/<user id>/program-devel/dist_linux/bin_linux/libprogramDLL.so: undefined symbol: h5lib_MP_h5get_libversion_f_

我认为链接静态库是一个问题,但不幸的是,我对CMake还是很陌生,无法隔离根本问题。我知道这个“符号”以某种方式绑定到libhdf5_fortran.a上,并且在我的缓存中列出了以下内容:

   $ grep -rnw '/nobackup/<user id>/program-devel/build' -e "libhdf5_fortran"
/nobackup/<user id>/program-devel/build/CMakeCache.txt:234:ToolkitLib_LIB_DEPENDS:STATIC=general;SomeLib;general;libz.a;general;libhdf5.a;general;libhdf5_fortran.a;

我不确定这是否是问题所在,但这来自ToolKit文件CMakeLists.txt。

if (${USE_HDF5})
      #link_directories (${HDF5_DIRECTORY}/lib)
      if (WIN32)
          target_link_libraries(ToolkitLib libszip libzlib libhdf5 libhdf5_f90cstub libhdf5_fortran)
      else ()

            # doesn't seem to work on Linux for some reason....
          #target_link_libraries(ToolkitLib libsz libz libhdf5 libhdf5_fortran)

          # ... try this ... seems to be getting the shared libs...not the static ones...
          # set(HDF5_LINK_FLAGS "-L${HDF5_DIRECTORY}/lib -lz -lhdf5_fortran -lhdf5")
          # SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${HDF5_LINK_FLAGS}")
          # SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${HDF5_LINK_FLAGS}")

            # ... doesn't work either ...
          target_link_libraries(ToolkitLib libz.a libhdf5.a libhdf5_fortran.a)

      endif()
endif()

最后4个“ target_link_library”元素位于我添加到LD_LIBRARY_PATH中的目录中(尽管我听说这不是首选方法)。当我发出gmake install时,还有一条最后的输出线可能是相关的:

    -- Set runtime path of "/nobackup/<user id>/program-devel/dist_linux/bin_linux/libProgramDLL.so" to "$ORIGIN/"

1 个答案:

答案 0 :(得分:0)

似乎我通过在hdf5安装bash脚本上添加String input = "1 2 fish1 1 2 fish2 1 2 fish3 1 2 fish1 1 2 fish2 1 2..."; String s = input.replaceFirst(Pattern.quote("fish1"), ""); 来解决问题。我还必须从--with-pic目录中的-standard-semantics中删除CMAKE_Fortran_FLAGS。这两件事以及您提供的帮助解决了我的问题。非常感谢Pierre de Buyl!