找不到符号 - 链接到 hdf 库
Symbol not found - linking to hdf library
我正在尝试使用 hdf5 格式来存储数据。问题是,我无法 link 反对图书馆。我有以下代码
#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
这总是returns错误
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
我做错了什么?
您包含了 HDF5 C++ 头文件,但只link包含了 HDF5 C 库。添加行: -lhdf5_cpp
到 link C++ 共享对象并使用 locate libhdf5_cpp
找到它的 libpath。
我正在尝试使用 hdf5 格式来存储数据。问题是,我无法 link 反对图书馆。我有以下代码
#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
这总是returns错误
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
我做错了什么?
您包含了 HDF5 C++ 头文件,但只link包含了 HDF5 C 库。添加行: -lhdf5_cpp
到 link C++ 共享对象并使用 locate libhdf5_cpp
找到它的 libpath。