Caffe在编译时找不到hdf5.h文件。

31
我在安装Python上的Caffe深度学习框架时遇到了问题:
当我在caffe目录下运行make命令时,它会显示

hdf5.h:没有这样的目录

我所做的步骤: 如果有人能帮助我,我将不胜感激。
错误信息:
CXX src/caffe/util/hdf5.cpp
in file include from src/caffe/util/hdf5.cpp:1:0:
./include/caffe/util/hdf5.hpp:6:18: fatal error: hdf5.h: No such file or directory
compilation terminated 

Makefile:572 recipe for target '.build_release/src/caffe/util/hdf5.o'       
failed Make:*** [.build_release/src/caffe/util/hdf5.o] Error 1

2
欢迎来到SO。请不要发布屏幕截图,而是将错误消息复制粘贴(并格式化)到您的问题中:这样搜索引擎可以更好地在未来定位此线程。 - Shai
2
你安装了HDF5吗?请看http:// caffe.berkeleyvision.org/install_apt.html: sudo apt-get install libhdf5-serial-dev - Shai
1
哦,对不起,我是新手,我会更改截图的。谢谢你通知我。是的,我已经安装了HDF5。 - kelvin
1
你的系统上有 hdf5.h 文件吗?尝试使用类似 locate hdf5.h 的命令来查找它的位置,并在这里发布结果。 - John Zwinck
1
嗨,我尝试在我的Ubuntu终端中按照您的建议编写“locate hdf5.h”,但没有任何反应。所以,我运行了另一个命令“find ~/ -type f -name“hdf5.h””,结果是“/home/kelvin/opencv-3.1.0/modules/flann/include/opencv2/flann/hdf5.h”。谢谢。 - kelvin
5个回答

64

你的Ubuntu安装版本是什么?尝试这样做。在你的Makefile.config中,尝试将/usr/include/hdf5/serial/添加到INCLUDE_DIRS中:

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

Makefile中的hdf5_hlhdf5重命名为hdf5_serial_hlhdf5_serial

--- 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

关于此漏洞修复,这里有更多信息。


1
谢谢。这节省了我的时间! - tobe
1
这是对我有效的解决方案!非常感谢! - Dang Manh Truong
这个答案确实是最佳解决方案(即不移动hdf5目录)。@kelvin:你能将这个答案标记为正确吗? - MarvMind
非常感谢。解决了我的问题。 - user3304797
1
这在Ubuntu 18.04上运行,无需添加LIBRARIES部分。 - jfleach
显示剩余3条评论

30

这个解决方案在Ubuntu16.04LTS上对我有效。

sudo apt-get install libhdf5-10
sudo apt-get install libhdf5-serial-dev
sudo apt-get install libhdf5-dev
sudo apt-get install libhdf5-cpp-11
find /usr -iname "*hdf5.h*"
/usr/include/hdf5/serial/hdf5.h
export CPATH="/usr/include/hdf5/serial/"

3
我也用过,有效! - O. Edholm
2
对我来说有效的三个! - Neo li
只需要运行 sudo apt-get install libhdf5-10 libhdf5-serial-dev 命令就可以了。 - Tony Z

4

我曾经遇到的另一个案例是:

我正在使用Ubuntu 14.04并安装hdf5-1.10.0

我发现hdf5.h位于/usr/local/hdf5/include。因此,我通过将该位置添加到INCLUDE_DIRS中来修改Makefile.config文件。

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include \
                    /usr/local/hdf5/include

我没有在Makefile中重命名任何东西。它正常工作。


4

在Ubuntu16.04 LTS上它对我不起作用。

所以我必须

sudo apt-get install libhdf5-10
sudo apt-get install libhdf5-serial-dev
sudo apt-get install libhdf5-dev
sudo apt-get install libhdf5-cpp-11
find /usr -iname "*hdf5.h*"
/usr/include/hdf5/serial/hdf5.h

现在进行这个操作

export CPATH="/usr/include/hdf5/serial/"

1
在RHEL7上,我厌倦了寻找特定的hdf5 RPM包,并运行了以下命令:
sudo yum install *hdf5*

这些是我所拥有的:

hdf5-openmpi3-static-1.8.12-11.el7.x86_64
hdf5-1.8.12-11.el7.x86_64
hdf5-openmpi-static-1.8.12-11.el7.x86_64
hdf5-openmpi3-devel-1.8.12-11.el7.x86_64
hdf5-openmpi3-1.8.12-11.el7.x86_64
hdf5-mpich-devel-1.8.12-11.el7.x86_64
hdf5-devel-1.8.12-11.el7.x86_64
hdf5-openmpi-devel-1.8.12-11.el7.x86_64
hdf5-mpich-static-1.8.12-11.el7.x86_64
hdf5-mpich-1.8.12-11.el7.x86_64
hdf5-openmpi-1.8.12-11.el7.x86_64

感谢 @loretoparisi 的帮助,我找到了缺失的头文件,问题得以解决。

$ find /usr -iname "*hdf5.h*"
/usr/include/openmpi-x86_64/hdf5.h
/usr/include/hdf5.h
/usr/include/mpich-x86_64/hdf5.h
/usr/include/openmpi3-x86_64/hdf5.h

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接