Ubuntu16.04安装CPU版Caffe报错:无法找到-lhdf5_hl
Hey there, I’ve run into this exact HDF5 linking issue before when setting up Caffe on Ubuntu 16.04—let’s get it sorted out step by step:
Step 1: Install the Missing HDF5 Development Libraries
First, make sure you have the full HDF5 development packages installed. The error pops up because the linker can’t locate the high-level HDF5 library (libhdf5_hl), which is part of the HDF5 development suite. Run this command to install it:
sudo apt-get update && sudo apt-get install libhdf5-dev libhdf5-serial-dev
Step 2: Update Caffe’s Makefile.config
Ubuntu 16.04 stores HDF5 headers and libraries in a serial subdirectory that Caffe’s default configuration doesn’t check. Open your Makefile.config file (copy Makefile.config.example if you haven’t already) and modify these sections:
Update Include Paths
Find the INCLUDE_DIRS line and add the HDF5 serial include directory:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
Update Library Paths
Find the LIBRARY_DIRS line and add the HDF5 serial library directory:
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial/
Step 3: (Optional) Fix Library Names in Makefile
If you still hit the error after updating paths, you might need to explicitly point to the serial versions of the HDF5 libraries in Caffe’s Makefile. Open the Makefile and replace instances of:
-lhdf5_hl -lhdf5
with:
-lhdf5_serial_hl -lhdf5_serial
Step 4: Recompile Caffe
Before rebuilding, clean up any partial builds to avoid conflicts:
make clean
Then start the build again (using -j$(nproc) to use all your CPU cores for faster compilation):
make all -j$(nproc)
Why This Happens
Ubuntu 16.04 packages HDF5 in a way that separates serial (non-parallel) libraries into a dedicated serial subdirectory. Caffe’s default configuration doesn’t include this path, so the linker can’t find libhdf5_hl.so and throws that error.
内容的提问来源于stack exchange,提问作者Harshit Nagar

