use*_*665 1 c++ cmake hdf5 linker-errors
我正在尝试编译一个简单的程序来读取 HDF5 文件。代码使用 h5c++ 正确编译。但是我需要一个相同的 cmakelists.txt
读取数据文件
#include <iostream>
#include "H5Cpp.h"
#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif
const H5std_string FILE_NAME( "testfile.h5" );
int main (void)
{
H5File openFile( FILE_NAME, H5F_ACC_RDONLY );
}
Run Code Online (Sandbox Code Playgroud)
我为它尝试了一个 cmakelists 但它没有用。它给出了“未定义的错误”
readdata.cpp:(.text+0x1d): undefined reference to `H5::FileAccPropList::DEFAULT'
readdata.cpp:(.text+0x24): undefined reference to `H5::FileCreatPropList::DEFAULT'
readdata.cpp:(.text+0x38): undefined reference to `H5check_version'
readdata.cpp:(.text+0x54): undefined reference to `H5::H5File::H5File(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, H5::FileCreatPropList const&, H5::FileAccPropList const&)'
readdata.cpp:(.text+0x60): undefined reference to `H5::H5File::~H5File()'
Run Code Online (Sandbox Code Playgroud)
CMakelists.txt
cmake_minimum_required(VERSION 3.1.0)
PROJECT (readhdf5)
find_package(HDF5 REQUIRED)
include_directories(${HDF5_INCLUDE_DIRS})
add_executable( readdata readdata.cpp )
target_link_libraries( readdata ${HDF5_CXX_LIBRARIES} ${HDF5_LIBRARIES})
Run Code Online (Sandbox Code Playgroud)
如果我手动放置 HDF5_CXX_LIBRARIES 和 HDF5_LIBRARIES,它就可以工作。
target_link_libraries( readdata libhdf5.so libhdf5_cpp.so)
Run Code Online (Sandbox Code Playgroud)
所以它无法读取 $HDF5_CXX_LIBRARIES 和 $HDF5_LIBRARIES。我该如何解决这个问题?
您尝试编译的代码取决于 HDF5 C++ 绑定,默认情况下,CMake 的 HDF5 模块不会搜索这些绑定。显式地将绑定添加到find_package
命令中:
find_package(HDF5 REQUIRED COMPONENTS C CXX)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1351 次 |
最近记录: |