Caffe: Fresh Install of Caffe Required Change to Makefile.config to Find HDF5 libs

Created on 8 Feb 2017  ·  1Comment  ·  Source: BVLC/caffe

Makefile (copy).config.txt

Issue summary

I had just completed an install of caffe on a new laptop, but when I ran make all, I got the following error:

 /usr/bin/ld: cannot find -lhdf5_hl
 /usr/bin/ld: cannot find -lhdf5
 collect2: error: ld returned 1 exit status
 Makefile:573: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed

My fix for this was to change the LIBRARY_DIRS assignment in Makefile.config to include the location of the hdf5 libs:

 LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib / usr/lib/x86_64-linux-gnu/hdf5/serial

and now things seem to work (make runtest just passed 2097 tests)

I also added /usr/include/hdf5/serial to INCLUDE_DIRS:

 INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial

Your system configuration

Operating system: Ubuntu 16.04.4
Compiler: gcc 5.4.0

Most helpful comment

Even after I added both LIBRARY_DIRS and INCLUDE_DIRS in Makefile.config as suggested above

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/aarch64-linux-gnu/hdf5/serial
````

But, I still got this error:

/usr/bin/ld: cannot find -lhdf5_hl
/usr/bin/ld: cannot find -lhdf5
collect2: error: ld returned 1 exit status
Makefile:573: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed

I have seen in some posts that we need create symbolics to find the libraries because the lib names of ```hdf5``` on debian have a postfix "serial", therefore ```-lhdf5``` and ```-lhdf5_hl``` cannot be found.

cd /usr/lib/x86_64-linux-gnu
sudo ln -s libhdf5_serial.so.8.0.2 libhdf5.so
sudo ln -s libhdf5_serial_hl.so.8.0.2 libhdf5_hl.so

But I am a user on a shared server, so I did not have ```sudo``` rights.

Also, a certain post suggested instead of changing symbolic links, we can just edit the ```Makefile``` in the caffe folder as such  

--- LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
+++ LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
```

Hope it'll help others searching for the solution

>All comments

Even after I added both LIBRARY_DIRS and INCLUDE_DIRS in Makefile.config as suggested above

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/aarch64-linux-gnu/hdf5/serial
````

But, I still got this error:

/usr/bin/ld: cannot find -lhdf5_hl
/usr/bin/ld: cannot find -lhdf5
collect2: error: ld returned 1 exit status
Makefile:573: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed

I have seen in some posts that we need create symbolics to find the libraries because the lib names of ```hdf5``` on debian have a postfix "serial", therefore ```-lhdf5``` and ```-lhdf5_hl``` cannot be found.

cd /usr/lib/x86_64-linux-gnu
sudo ln -s libhdf5_serial.so.8.0.2 libhdf5.so
sudo ln -s libhdf5_serial_hl.so.8.0.2 libhdf5_hl.so

But I am a user on a shared server, so I did not have ```sudo``` rights.

Also, a certain post suggested instead of changing symbolic links, we can just edit the ```Makefile``` in the caffe folder as such  

--- LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
+++ LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
```

Hope it'll help others searching for the solution

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FreakTheMighty picture FreakTheMighty  ·  3Comments

erogol picture erogol  ·  3Comments

vladislavdonchev picture vladislavdonchev  ·  3Comments

hawklucky picture hawklucky  ·  3Comments

dfotland picture dfotland  ·  3Comments