6

I just started with C and also with HDF5 so my question might be very easy to answer.

I tried an example-code from http://beige.ucs.indiana.edu/I590/node122.html to create an HDF5 file.

#include "hdf5.h"
#define FILE "file.h5"
main() {
 hid_t file_id; /* file identifier */
 herr_t status;
 /* Create a new file using default properties. */
 file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
 /* Terminate access to the file. */
 status = H5Fclose(file_id);
}

I tried to compile this with Eclipse and got 5 error messages:

make: *** [Read_HDF5] Error 1
skipping incompatible /usr/lib/libc.so when searching for -lc
undefined reference to `H5check_version'
undefined reference to `H5Fcreate'
undefined reference to `H5Fclose'

What went wrong?

Thanks for you help!!!

Simon
33.2k9 gold badges84 silver badges94 bronze badges
asked Mar 18, 2014 at 15:13

1 Answer 1

6

You need to link the HDF5 library when compiling. The errors you get mean the code for these functions is missing, because you didn't link the library file that contains them. The easiest way is to compile using h5cc as described in the tutorial you mentioned. Otherwise, if you prefer compiling in Eclipse, you need to search for the linker flags setting and add the correct flags which you can find by typing h5cc -show in a terminal.

For instance, for me, h5cc -show gives

clang -I/usr/local/include -L/usr/local/Cellar/hdf5/1.8.12/lib /usr/local/Cellar/hdf5/1.8.12/lib/libhdf5_hl.a /usr/local/Cellar/hdf5/1.8.12/lib/libhdf5.a -L/usr/local/lib -lsz -lz -ldl -lm

Piece by piece:

  • clang is the compiler

  • -I/usr/local/include is a flag telling the compiler to search for header files inside the /usr/local/include directory

  • -L/usr/local/Cellar/hdf5/1.8.12/lib and -L/usr/local/lib are flags telling the linker to search for libraries inside these directories

  • /usr/local/Cellar/hdf5/1.8.12/lib/libhdf5_hl.a and /usr/local/Cellar/hdf5/1.8.12/lib/libhdf5.a are the full path to two HDF5 static libraries (telling the linker to link them)

  • -lsz, -lz, -ldl and -lm are flags telling the linker to link the libraries sz, z, dl and m

This is probably overkill. If your HDF5 is installed in a standard location, it might be enough to just add -lhdf5 to the linker flags.

answered Mar 18, 2014 at 21:44
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I got how to fix my problem: I included the Library for 32-bit systems as well as the Library for 64-bit Systems. Thats where the skipping-error message comes from. Thank you!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.