找不到符号 - 链接到hdf库

时间:2015-12-02 18:20:22

标签: linker hdf

我正在尝试使用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

我在这里做错了什么?

1 个答案:

答案 0 :(得分:2)

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