用于编译HDF5的CMakelists.txt?

时间:2017-01-08 05:25:27

标签: c++ cmake linker-errors hdf5

我正在尝试编译一个简单的程序来读取HDF5文件。代码用h5c ++正确编译。但是我需要一个cmakelists.txt用于相同的

readdata.cpp

#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 );
}

我尝试了一个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()'

的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})

如果我手动放置HDF5_CXX_LIBRARIES和HDF5_LIBRARIES,它就能正常工作。

target_link_libraries( readdata libhdf5.so libhdf5_cpp.so)

所以它无法读取$ HDF5_CXX_LIBRARIES和$ HDF5_LIBRARIES。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

您尝试编译的代码取决于HDF5 C ++绑定,默认情况下CMake的HDF5模块不会搜索这些绑定。将绑定显式添加到find_package(HDF5 REQUIRED COMPONENTS C CXX) 命令:

dialplan reload