gpt4 book ai didi

c++ - HDF5 - C++ - 打开文件读取内容失败

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:27:31 29 4
gpt4 key购买 nike

我尝试编写一个非常短的脚本来打开一个 hdf5 文件,但它不起作用。

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

}

我很确定我包含了 hdf5 库和包含的路径。但是尽管如此,我还是从链接器收到了错误消息:

Invoking: GCC C++ Linker
g++ -L/usr/local/pub/lib64 -L/usr/local/pub/lib -L/lib64 -L/usr/lib64 -o "HDF5_CPP" ./openfile.o
./openfile.o: In function `main':
/athome/augs_ay/workspace/HDF5_CPP/Debug/../openfile.cpp:18: undefined reference to `H5check_version'
/athome/augs_ay/workspace/HDF5_CPP/Debug/../openfile.cpp:18: undefined reference to `H5::FileAccPropList::DEFAULT'
/athome/augs_ay/workspace/HDF5_CPP/Debug/../openfile.cpp:18: undefined reference to `H5::FileCreatPropList::DEFAULT'
/athome/augs_ay/workspace/HDF5_CPP/Debug/../openfile.cpp:18: undefined reference to `H5::H5File::H5File(std::string const&, unsigned int, H5::FileCreatPropList const&, H5::FileAccPropList const&)'
/athome/augs_ay/workspace/HDF5_CPP/Debug/../openfile.cpp:18: undefined reference to `H5::H5File::~H5File()'
collect2: error: ld returned 1 exit status
make: *** [HDF5_CPP] Error 1

有人可以帮忙吗?谢谢!

最佳答案

对于那些使用 CMake 的人,这里有一个例子:

( undefined reference 问题在最后一行解决)

find_package(HDF5 COMPONENTS C CXX HL REQUIRED)
link_directories( ${HDF5_LIBRARY_DIRS} )
include_directories( ${HDF5_INCLUDE_DIRS} )
add_executable( convert_to_hdf5 src/convert_to_hdf5.cpp )
target_link_libraries( convert_to_hdf5 ${HDF5_CXX_LIBRARIES} )

关于c++ - HDF5 - C++ - 打开文件读取内容失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22664630/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com