Solvedcaffe caffe fails with error undefined reference to cv::imread(cv::String const&, int)' and undefined reference to cv::imdecode(cv::_InputArray const&, int)

I am trying to compile and use the latest version of caffe , but I'm getting these errors

AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
CXX tools/caffe.cpp
CXX/LD -o .build_release/tools/caffe.bin
.build_release/lib/libcaffe.so: undefined reference to `cv::imread(cv::String const&, int)'
.build_release/lib/libcaffe.so: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > 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/caffe.bin] Error 1

I downloaded caffe almost a month a go and that compiled just fine! but this one that I downloaded today! gives these errors:

I tried the hongzhenwang solution here but that didnt work for me!
Whats wrong and how can I get rid of these errors?

by the way I installed opencv using this command on ubuntu 14.04 :

sudo apt-get install libopencv-dev

Thanks in advance

27 Answers

✔️Accepted Answer

I think you may be using OpenCV 3. You need to set the OPENCV_VERSION variable in Makefile.config.

Other Answers:

vra
214

I am using a older version of caffe in another repo(actually, RstarCNN) and there isn't the parameter OPENCV_VERSION in that version of caffe. I just uncommented # USE_PKG_CONFIG := 1 and the make command passed. Hope this info can be helpful for someone.

make clean the caffe, try sudo ldconfig before make. Will this help?

Ok, I added the opencv libs from anacondas Lib directory to the bashrc like this:

export LD_LIBRARY_PATH=/home/hossein/anaconda2/lib:$LD_LIBRARY_PATH

So far the make runtest is going just well, I hope what I am doing is Ok and doesnt create any more issues!
Update:
Thanks to dear God, I could successfully train mnist .:)
Thank you everyone

I just uncommended OPENCV_VERSION := 3 and solved the problem, wish it helps.

More Issues: