3

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?

physicsGuy
  • 3,437
  • 3
  • 27
  • 35
  • Why do you compile with gcc? Have you tried using g++ instead? – sestus Dec 02 '15 at 18:24
  • g++ yields the same errors. I used the following command `g++ -std=c++11 -o main main.cpp -I /usr/local/include/ -L /usr/local/lib/ -lhdf5 -lhdf5_hl` – physicsGuy Dec 02 '15 at 18:43

1 Answers1

4

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.

user14717
  • 4,757
  • 2
  • 44
  • 68
  • I am facing the same problem. Can you explain this in more detail :)? fyi: My hdf files are in the location '/usr/local/lib'. – Vivek Bagaria Sep 08 '17 at 00:01
  • 1
    @VivekBagaria: I would suggest not using the C++ bindings to HDF5, just use the C bindings. The C++ bindings are not maintained very well. – user14717 Sep 08 '17 at 01:06