4

I've installed libhdf5-dev with apt-get but gcc cannot find it:

~$ locate libhdf5.so
/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so
~$ gcc -lhdf5
/usr/bin/ld: cannot find -lhdf5
collect2: error: ld returned 1 exit status

I'm on Ubuntu 17.10.

Yaron
  • 13,453

1 Answers1

1

In order to help ld to find your hdf5 library you can add the following flag:

-L /usr/lib/x86_64-linux-gnu/hdf5/serial

i.e.

~$ gcc -lhdf5 -L/usr/lib/x86_64-linux-gnu/hdf5/serial

man gcc

-Ldir
   Add directory dir to the list of directories to be searched for -l.

Official install instructions

Configure the HDF5 version

Note: this is a quick fix for a minor bug / issue with the version of libhdf5. If you know a better / proper way to solve it, let me know. If this section doesn't apply to you, omit it.

  1. Go to the libraries directory:

    cd /usr/lib/x86_64-linux-gnu
    
  2. Set LD_LIBRARY_PATH for libraries in Anacoda, such as libhdf5.so.10, libhdf5_hl.so.10:

    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/ubuntu/anaconda/lib" >> ~/.bashrc
    
  3. Update the "Dynamic Linker":

    sudo ldconfig
    
Yaron
  • 13,453