Caffe 工程的一些編譯錯誤以及解決方案(undefined reference to cv::imread)
原文連結:http://blog.csdn.net/yhl_leo/article/details/51371936
在編譯caffe時遇到了該博文的第二種情況,改正後可以正確執行:
(注意根據電腦情況可使用make all -j16)
整理一下最近遇到caffe工程的一些編譯錯誤以及解決方法。
1 cuDNN
cuDNN當前最新版本是v5,近兩三年的一些caffe工程,使用的版本不盡相同,其中以v2/v3版本的最為常見,所以使用的時候一定要搞清楚(當然如果作者沒說,那就自己依次嘗試吧)。
cuDNN出現版本不匹配,在工程make
的時候,會報如下錯誤(以安裝v4版本,編譯v3版本的程式為例)
NVCC src/caffe/layers/deconv_layer.cu
NVCC src/caffe/layers/cudnn_conv_layer.cu
src/caffe/layers/cudnn_conv_layer.cu(81): error: argument of type "cudnnAddMode_t" is
incompatible with parameter of type "const void *"
detected during instantiation of "void
caffe::CuDNNConvolutionLayer<Dtype>::Forward_gpu(const std::vector<caffe::Blob<Dtype> *,
std::allocator<caffe::Blob<Dtype> *>> &, const std::vector<caffe::Blob<Dtype> *,
std::allocator<caffe::Blob<Dtype> *>> &) [with Dtype=float]"
(157): here
...
20 errors detected in the compilation of "/tmp/tmpxft_00002703_00000000-
16_cudnn_conv_layer.compute_50.cpp1.ii".
make: *** [.build_release/cuda/src/caffe/layers/cudnn_conv_layer.o] Error 1
make: *** Waiting for unfinished jobs....
解決方案是這樣的,下載v3版本,解壓後,在終端進入所在資料夾下(這裡仍然以v3版本為例)
$ cd lib64/
$ sudo cp lib* /usr/local/cuda/lib64/
$ cd ../include/
$ sudo cp cudnn.h /usr/local/cuda/include/
$ cd /usr/local/cuda/lib64/
$ sudo rm -r libcudnn.so libcudnn.so.7.0
$ sudo ln -sf libcudnn.so.7.0.64 libcudnn.so.7.0
$ sudo ln -sf libcudnn.so.7.0 libcudnn.so
$ sudo ldconfig
2 OpenCV
我使用的版本是3.1.0
,在編譯工程的時候,遇到如下BUG
...CXX/LD -o .build_release/tools/convert_imageset.bin .build_release/lib/libcaffe.so: undefined reference to cv::imread(cv::String const&, int)’ .build_release/lib/libcaffe.so: undefined reference tocv::imencode(cv::String const&, cv::_InputArray const&, std::vector >&, std::vector > const&)’ .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode(cv::_InputArray const&, int)’ collect2: error: ld returned 1 exit status make: * [.build_release/tools/convert_imageset.bin] Error 1
...
首先,我是已經配置過了opencv的,可以這樣查詢安裝版本:
$ pkg-config --modversion opencv
因為編譯好了,理所當然,輸出結果是3.1.0
所以出現上面的錯誤,應該是opencv_imgcodecs
連結的問題,比較有效的解決方案是,把opencv需要的lib新增到Makefile
檔案中,找到LIBRARIES
(在PYTHON_LIBRARIES
:= boost_python python2.7
前一行)並修改為:
LIBRARIES += glog gflags protobuf leveldb snappy \ lmdb boost_system hdf5_hl hdf5 m \ opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
3 make
每次需要重新編譯的過程中,首先需要清除掉以往編譯的結果:
$make clean
然後再重新編譯:
$ make all -j12
$ make distribute
$ make pycaffe
$ make matcaffe
-j12
的含義是run
12 jobs in parallel
,看自己機器的效能,自己設定,可以更快編譯。