【问题标题】:HDF5 - C++ - open a file to read the contents failedHDF5 - C++ - 打开文件以读取内容失败
【发布时间】:2014-05-05 01:40:21
【问题描述】:

我尝试编写一个非常短的脚本来打开一个 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

谁能帮忙? 谢谢!

【问题讨论】:

  • 您需要将-lhdf5_cpp -lhdf5 添加到您的构建命令中。
  • 我正在使用 Eclipse 进行构建。我该怎么做?
  • 啊,我找到了!属性 - C/C++ 构建 - 设置 - 链接器库 谢谢!成功了

标签: c++ linker-errors hdf5


【解决方案1】:

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

(未定义的引用问题在最后一行解决)

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

【讨论】:

    【解决方案2】:

    我只是想给以后到达这个地方并遇到同样问题的其他人留个便条:

    如果您选择使用 g++ 和标志来编译您的代码,而不是 hdf5 提供的 h5c++ 脚本,请确保您使用的标志来自 h5c++ -show 而不是 h5cc -show,因为后者用于直接 C 版本。

    【讨论】:

      猜你喜欢
      • 2017-03-19
      • 2016-09-21
      • 1970-01-01
      • 2014-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-29
      相关资源
      最近更新 更多