编译另一个库时出现 HDF5 错误
Posted
技术标签:
【中文标题】编译另一个库时出现 HDF5 错误【英文标题】:HDF5 error while compiling another library 【发布时间】:2017-02-23 04:40:13 【问题描述】:我按照以下步骤编译了 HDF5:
untar hdf5-xxx.tar.gz
cd hdf5-xxx
make
make install
但是,当我安装另一个请求 HDF5 的库 (OpenGM) 时,我给出了以下参数:
HDF5_CORE_LIBRARY /Users/Florian/Documents/THESE/hdf5-1.8.7/hdf5
HDF5_CPP_LIBRARY /Users/Florian/Documents/THESE/hdf5-1.8.7/c++
HDF5_HL_LIBRARY /Users/Florian/Documents/THESE/hdf5-1.8.7/hl
HDF5_INCLUDE_DIR /Users/Florian/Documents/THESE/hdf5-1.8.7/hdf5/include
HDF5_Z_LIBRARY /usr/lib/libz.dylib
使用 CMake 并生成后,我得到:
WARNING: Target "example-io" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hdf5". Targets may link only to libraries.
CMake is dropping the item.
WARNING: Target "example-io" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hl". Targets may link only to libraries.
CMake is dropping the item.
WARNING: Target "external-library-daoopt" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hdf5". Targets may link only
to libraries. CMake is dropping the item.
WARNING: Target "external-library-daoopt" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hl". Targets may link only to
libraries. CMake is dropping the item.
WARNING: Target "external-library-daoopt-shared" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hdf5". Targets may
link only to libraries. CMake is dropping the item.
WARNING: Target "external-library-daoopt-shared" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hl". Targets may link
only to libraries. CMake is dropping the item.
WARNING: Target "_opengmcore" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hdf5". Targets may link only to
libraries. CMake is dropping the item.
WARNING: Target "_opengmcore" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hdf5". Targets may link only to
libraries. CMake is dropping the item.
WARNING: Target "_opengmcore" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hl". Targets may link only to libraries.
CMake is dropping the item.
WARNING: Target "_hdf5" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hdf5". Targets may link only to libraries.
CMake is dropping the item.
WARNING: Target "_hdf5" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hl". Targets may link only to libraries. CMake
is dropping the item.
WARNING: Target "modelIO" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hdf5". Targets may link only to libraries.
CMake is dropping the item.
WARNING: Target "modelIO" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hl". Targets may link only to libraries.
CMake is dropping the item.
WARNING: Target "buildFoE" requests linking to directory "/Users/Florian/Documents/THESE/hdf5-1.8.7/hdf5". Targets may link only to libraries.
CMake is dropping the item.
因为这些只是“只是”警告,我可以编译我的 OpenGM 库:
make
但我因此最终出现以下错误:
Undefined symbols for architecture x86_64:
"_H5Aclose", referenced from:
void marray::hdf5::save<unsigned long>(int const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, marray::Marray<unsigned long, std::__1::allocator<unsigned long> > const&) in io_graphical_model.cxx.o
void marray::hdf5::save<float>(int const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, marray::Marray<float, std::__1::allocator<unsigned long> > const&) in io_graphical_model.cxx.o
void marray::hdf5::save<double>(int const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, marray::Marray<double, std::__1::allocator<unsigned long> > const&) in io_graphical_model.cxx.o
void marray::hdf5::save<long>(int const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, marray::Marray<long, std::__1::allocator<unsigned long> > const&) in io_graphical_model.cxx.o
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
由于警告和错误都处理 HDF5,我想主要问题来自这个库。
如果有帮助,我正在使用 MacOSX。
**编辑:**添加 FindHDF5.cmake 文件
# - Find HDF5, a library for reading and writing self describing array data.
#
FIND_PATH(HDF5_INCLUDE_DIR hdf5.h)
FIND_LIBRARY(HDF5_CORE_LIBRARY NAMES hdf5dll hdf5 )
FIND_LIBRARY(HDF5_HL_LIBRARY NAMES hdf5_hldll hdf5_hl )
FIND_LIBRARY(HDF5_CPP_LIBRARY NAMES hdf5_cppdll hdf5_cpp )
IF(WIN32 AND HDF5_CORE_LIBRARY MATCHES "dll.lib$")
SET(HDF5_CFLAGS "-D_HDF5USEDLL_")
SET(HDF5_CPPFLAGS "-D_HDF5USEDLL_ -DHDF5CPP_USEDLL")
ELSE()
SET(HDF5_CFLAGS)
SET(HDF5_CPPFLAGS)
ENDIF()
SET(HDF5_VERSION_MAJOR 1)
SET(HDF5_VERSION_MINOR 8)
set(HDF5_SUFFICIENT_VERSION FALSE)
TRY_COMPILE(HDF5_SUFFICIENT_VERSION
$CMAKE_BINARY_DIR $CMAKE_MODULE_PATH/checkHDF5version.c
COMPILE_DEFINITIONS "-I\"$HDF5_INCLUDE_DIR\" -DMIN_MAJOR=$HDF5_VERSION_MAJOR -DMIN_MINOR=$HDF5_VERSION_MINOR")
if(HDF5_SUFFICIENT_VERSION)
MESSAGE(STATUS
"Checking HDF5 version (at least $HDF5_VERSION_MAJOR.$HDF5_VERSION_MINOR): ok")
else()
MESSAGE( STATUS "HDF5: need at least version $HDF5_VERSION_MAJOR.$HDF5_VERSION_MINOR" )
endif()
set(HDF5_USES_ZLIB FALSE)
TRY_COMPILE(HDF5_USES_ZLIB
$CMAKE_BINARY_DIR $CMAKE_MODULE_PATH/checkHDF5usesCompression.c
COMPILE_DEFINITIONS "-I\"$HDF5_INCLUDE_DIR\" -DH5_SOMETHING=H5_HAVE_FILTER_DEFLATE")
if(HDF5_USES_ZLIB)
FIND_LIBRARY(HDF5_Z_LIBRARY NAMES zlib1 zlib z )
set(HDF5_ZLIB_OK $HDF5_Z_LIBRARY)
else()
set(HDF5_ZLIB_OK TRUE)
set(HDF5_Z_LIBRARY "")
endif()
set(HDF5_USES_SZLIB FALSE)
TRY_COMPILE(HDF5_USES_SZLIB
$CMAKE_BINARY_DIR $CMAKE_MODULE_PATH/checkHDF5usesCompression.c
COMPILE_DEFINITIONS "-I\"$HDF5_INCLUDE_DIR\" -DH5_SOMETHING=H5_HAVE_FILTER_SZIP")
if(HDF5_USES_SZLIB)
FIND_LIBRARY(HDF5_SZ_LIBRARY NAMES szlibdll sz )
set(HDF5_SZLIB_OK $HDF5_SZ_LIBRARY)
else()
set(HDF5_SZLIB_OK TRUE)
set(HDF5_SZ_LIBRARY "")
endif()
# handle the QUIETLY and REQUIRED arguments and set HDF5_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(HDF5 DEFAULT_MSG HDF5_CORE_LIBRARY
HDF5_HL_LIBRARY HDF5_ZLIB_OK HDF5_SZLIB_OK HDF5_INCLUDE_DIR)
IF(HDF5_FOUND)
SET(HDF5_LIBRARIES $HDF5_CORE_LIBRARY $HDF5_HL_LIBRARY $HDF5_Z_LIBRARY $HDF5_SZ_LIBRARY)
ELSE()
SET(HDF5_CORE_LIBRARY HDF5_CORE_LIBRARY-NOTFOUND)
SET(HDF5_HL_LIBRARY HDF5_HL_LIBRARY-NOTFOUND)
SET(HDF5_Z_LIBRARY HDF5_Z_LIBRARY-NOTFOUND)
SET(HDF5_SZ_LIBRARY HDF5_SZ_LIBRARY-NOTFOUND)
ENDIF(HDF5_FOUND)
【问题讨论】:
... where I provide the path to the HDF5 library ...
- 看起来您将 directory 分配给了一个变量,该变量应该是一个 库文件。这就是你发出警告的原因。
查看我的编辑以查看我作为 CMake 参数给出的内容。
正如我之前所说的:您将目录分配给变量(HDF5_CORE_LIBRARY
,HDF5_HL_LIBRARY
),它应该是一个库文件。
你对库的定义是什么?我应该考虑哪些扩展?
您通过find_package(HDF5)
获得此变量列表,不是吗?与其手动填充这些变量,不如提示这个安装HDF5库的过程。 FindHDF5.cmake
脚本中的注释描述了如何提示它。跟着他们就行了。
【参考方案1】:
通过编译带有--with_cxx
标志的HDF5 库来构建C++ 接口解决了这个问题。另外我把HDF5库安装在/usr/local
,这样安装opengm的时候就自动找到了。
【讨论】:
我遇到了类似的问题。问题是,尽管我可以成功编译 OpenGM,但我无法编译调用 opengm 库和 hdf5 的简单 c++ 文件。以上是关于编译另一个库时出现 HDF5 错误的主要内容,如果未能解决你的问题,请参考以下文章
编译代码时出现此错误,我已从另一个系统复制代码。我该如何解决这个错误?
使用 qt creator 和 eigen 库编译程序时出现 lnk2019 错误
使用 Electron 编译 node.js 版本时出现问题