[环境配置]Ubuntu 16.04+CUDA 9.0+OpenCV 3.2.0下编译Caffe踩过的一些坑

本文详细介绍了在Ubuntu16.04环境下,使用CUDA9.0和OpenCV3.2.0编译Caffe过程中遇到的hdf5缺失、OpenCV3和架构不兼容等问题的解决方案。包括hdf5的下载、编译、链接,更新cmake版本,配置Makefile.config,以及解决特定版本的CUDA架构问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境:Ubuntu 16.04,CUDA 9.0,OpenCV 3.2.0

原则:make报错然后修改,之后再次make之前要make clean一下,有时候就是没有clean所以仍然失败。

1、hdf5缺失

解决方案

官网下载hdf5

https://www.hdfgroup.org/downloads/hdf5/source-code/

解压后编译安装

$ cd hdf5-1.10.3
$ mkdir build
$ cd build
$ cmake ..
$ sudo make
$ sudo make install

对于新版本的hdf5需要较新版本的cmake,因此需要将cmake更新至3.10以后,此处选择3.12.0

$ cd /usr
$ sudo wget https://cmake.org/files/v3.12/cmake-3.12.0-Linux-x86_64.tar.gz
$ sudo tar zxvf cmake-3.12.0-Linux-x86_64.tar.gz
$ sudo ln -s /usr/cmake-3.12.0-Linux-x86_64/bin/* /usr/bin/

如果提示有冲突,那么需要将原有的cmake相关可执行文件删除

$ sudo rm /usr/bin/cmake #以及其他如ccmake、ctest、cpack、cmake-gui
#然后重新关联
$ sudo ln -s /usr/cmake-3.12.0-Linux-x86_64/bin/* /usr/bin/

$ cmake --version #检查cmake版本,如果为3.12.0则说明安装成功

打开Makefile.config,找到

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

改为

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

然后链接hdf5库

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

如果还是有问题

$ sudo ln -sf libhdf5_serial.so libhdf5.so
$ sudo ln -sf libhdf5_serial_hl.so libhdf5_hl.so

github讨论链接https://github.com/BVLC/caffe/issues/4333

2、opencv3的问题

问题如下

.build_release/lib/libcaffe.so: undefined reference to 'cv::VideoCapture::set(int, double)'
...

解决方案

已安装opencv3及对应的contrib的同学们打开Makefile.config,找到

# OPENCV_VERSION := 3

将这句话前面的#去掉,然后打开Makefile找到

ifeq ($(USE_OPENCV), 1)
    LIBRARIES += opencv_core opencv_highgui opencv_imgproc

这里空格然后加上

opencv_imgcodecs opencv_contrib opencv_videoio

3、架构architecture compute_20的问题

问题如下

nvcc fatal   : Unsupported gpu architecture 'compute_20'
Makefile:596: recipe for target '.build_release/cuda/src/caffe/solvers/nesterov_solver.o' failed

解决方案

打开Makefile.config,找到

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the lines after *_35 for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
             -gencode arch=compute_20,code=sm_21 \
             -gencode arch=compute_30,code=sm_30 \
             -gencode arch=compute_35,code=sm_35 \
             -gencode arch=compute_50,code=sm_50 \
             -gencode arch=compute_52,code=sm_52 \
             -gencode arch=compute_61,code=sm_61

第三行和第四行中的结构部分前面加#,改为

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the lines after *_35 for compatibility.
CUDA_ARCH := #-gencode arch=compute_20,code=sm_20 \
             #-gencode arch=compute_20,code=sm_21 \
             -gencode arch=compute_30,code=sm_30 \
             -gencode arch=compute_35,code=sm_35 \
             -gencode arch=compute_50,code=sm_50 \
             -gencode arch=compute_52,code=sm_52 \
             -gencode arch=compute_61,code=sm_61

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值