Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symbol not found - linking to hdf library

Tags:

linker

hdf

I am trying to use the hdf5-format to store data. Problem is, that I fail to link against the library. I have the following code

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

and compile it using

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

This always returns the error

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)

I installed the hdf5 library on OSX using

brew install homebrew/science/hdf5

What am I doing wrong here?

like image 429
physicsGuy Avatar asked Aug 31 '25 18:08

physicsGuy


1 Answers

You are including the HDF5 C++ header file, but only linking the HDF5 C library. Add the line: -lhdf5_cpp to link the C++ shared object and use locate libhdf5_cpp to find it's libpath.

like image 87
user14717 Avatar answered Sep 02 '25 09:09

user14717