CMakelists.txt 用于编译 HDF5?
CMakelists.txt for compiling 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 但它没有用。它给了 "not defined errors"
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.How 我可以解决这个问题吗?
您尝试编译的代码依赖于 HDF5 C++ 绑定,CMake 的 HDF5 模块默认不搜索这些绑定。将绑定显式添加到 find_package
命令:
find_package(HDF5 REQUIRED COMPONENTS C CXX)
我正在尝试编译一个简单的程序来读取 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 但它没有用。它给了 "not defined errors"
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.How 我可以解决这个问题吗?
您尝试编译的代码依赖于 HDF5 C++ 绑定,CMake 的 HDF5 模块默认不搜索这些绑定。将绑定显式添加到 find_package
命令:
find_package(HDF5 REQUIRED COMPONENTS C CXX)