3

我正在尝试使用 hdf5 格式来存储数据。问题是,我无法链接到图书馆。我有以下代码

#include <H5Cpp.h>
int main(void){
    H5::H5File file("test_MatrixRoundTrip_Double.h5", H5F_ACC_TRUNC);
}

并使用

gcc -std=c++11 -o main main.cpp -I /usr/local/include/ -L /usr/local/lib/ -lhdf5 -lhdf5_hl

这总是返回错误

Undefined symbols for architecture x86_64:
  "H5::FileAccPropList::DEFAULT", referenced from:
  _main in main-c207d1.o
  "H5::FileCreatPropList::DEFAULT", referenced from:
  _main in main-c207d1.o
  "H5::H5File::H5File(char const*, unsigned int, H5::FileCreatPropList const&, H5::FileAccPropList const&)", referenced from:
  _main in main-c207d1.o
  "H5::H5File::~H5File()", referenced from:
  _main in main-c207d1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我使用在 OSX 上安装 hdf5 库

brew install homebrew/science/hdf5

我在这里做错了什么?

4

1 回答 1

3

您包括 HDF5 C++ 头文件,但仅链接 HDF5 C 库。添加以下行:-lhdf5_cpp链接 C++ 共享对象并使用locate libhdf5_cpp它来查找它的 libpath。

于 2015-12-09T22:32:21.427 回答