Solvedcaffe .build_release/lib/libcaffe.so: undefined reference to `cv::imdecode

I get this error:

CXX examples/mnist/convert_mnist_data.cpp
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: cannot find -lcudnn
collect2: error: ld returned 1 exit status
Makefile:554: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed

Hence:

jalal@klein:~/computer_vision/py-faster-rcnn/caffe-fast-rcnn$ sudo cp -r /home/jalal/cudnn/cuda/lib64/* /usr/local/cuda/lib64
jalal@klein:~/computer_vision/py-faster-rcnn/caffe-fast-rcnn$ ls
build       cmake           CONTRIBUTING.md  data        docs      include     LICENSE   Makefile.config          matlab  python     scripts  tools
caffe.cloc  CMakeLists.txt  CONTRIBUTORS.md  distribute  examples  INSTALL.md  Makefile  Makefile.config.example  models  README.md  src
jalal@klein:~/computer_vision/py-faster-rcnn/caffe-fast-rcnn$ make -j8 && make pycaffe
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
CXX/LD -o .build_release/tools/upgrade_net_proto_text.bin
CXX/LD -o .build_release/tools/train_net.bin
CXX/LD -o .build_release/tools/compute_image_mean.bin
CXX/LD -o .build_release/tools/upgrade_net_proto_binary.bin
CXX/LD -o .build_release/tools/test_net.bin
CXX/LD -o .build_release/tools/convert_imageset.bin
CXX/LD -o .build_release/tools/device_query.bin
CXX/LD -o .build_release/tools/finetune_net.bin
CXX/LD -o .build_release/tools/caffe.bin
CXX/LD -o .build_release/tools/extract_features.bin
CXX/LD -o .build_release/tools/upgrade_solver_proto_text.bin
CXX/LD -o .build_release/tools/net_speed_benchmark.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
Makefile:607: recipe for target '.build_release/tools/compute_image_mean.bin' failed
make: *** [.build_release/tools/compute_image_mean.bin] Error 1
make: *** Waiting for unfinished jobs....
.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
Makefile:607: recipe for target '.build_release/tools/upgrade_net_proto_binary.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1
.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
Makefile:607: recipe for target '.build_release/tools/convert_imageset.bin' failed
make: *** [.build_release/tools/convert_imageset.bin] Error 1
.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
Makefile:607: recipe for target '.build_release/tools/upgrade_net_proto_text.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_text.bin] Error 1
.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
Makefile:607: recipe for target '.build_release/tools/caffe.bin' failed
make: *** [.build_release/tools/caffe.bin] Error 1
.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
Makefile:607: recipe for target '.build_release/tools/upgrade_solver_proto_text.bin' failed
make: *** [.build_release/tools/upgrade_solver_proto_text.bin] Error 1
.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
Makefile:607: recipe for target '.build_release/tools/extract_features.bin' failed
make: *** [.build_release/tools/extract_features.bin] Error 1
jalal@klein:~/computer_vision/py-faster-rcnn/caffe-fast-rcnn$ ls /usr/local/cuda/lib64
libcublas_device.a   libcudnn.so         libcufftw.so.7.5.18   libcusolver.so         libnppc.so.7.5.18  libnvblas.so                 libnvToolsExt.so.1
libcublas.so         libcudnn.so.4       libcufftw_static.a    libcusolver.so.7.5     libnppc_static.a   libnvblas.so.7.5             libnvToolsExt.so.1.0.0
libcublas.so.7.5     libcudnn.so.4.0.7   libcuinj64.so         libcusolver.so.7.5.18  libnppi.so         libnvblas.so.7.5.18          libOpenCL.so
libcublas.so.7.5.18  libcudnn_static.a   libcuinj64.so.7.5     libcusolver_static.a   libnppi.so.7.5     libnvrtc-builtins.so         stubs
libcublas_static.a   libcufft.so         libcuinj64.so.7.5.18  libcusparse.so         libnppi.so.7.5.18  libnvrtc-builtins.so.7.5
libcudadevrt.a       libcufft.so.7.5     libculibos.a          libcusparse.so.7.5     libnppi_static.a   libnvrtc-builtins.so.7.5.18
libcudart.so         libcufft.so.7.5.18  libcurand.so          libcusparse.so.7.5.18  libnpps.so         libnvrtc.so
libcudart.so.7.5     libcufft_static.a   libcurand.so.7.5      libcusparse_static.a   libnpps.so.7.5     libnvrtc.so.7.5
libcudart.so.7.5.18  libcufftw.so        libcurand.so.7.5.18   libnppc.so             libnpps.so.7.5.18  libnvrtc.so.7.5.17
libcudart_static.a   libcufftw.so.7.5    libcurand_static.a    libnppc.so.7.5         libnpps_static.a   libnvToolsExt.so
jalal@klein:~/computer_vision/py-faster-rcnn/caffe-fast-rcnn$ ls -ltr /usr/local/cuda/lib64
lrwxrwxrwx 1 root root 24 Aug 15  2015 /usr/local/cuda/lib64 -> targets/x86_64-linux/lib

I have Cuda7.5 and CuDNN V4 on Ubuntu 15.10 64bit. I have Python 3 and OpenCV3 (for Python) Installed!

16 Answers

✔️Accepted Answer

Hi @monajalal Have you noticed the 21st line in Makefile.config.example which is
# OPENCV_VERSION := 3
To use OpenCV 3.X with Caffe, you should uncomment this line. You can refer to the 197th line in Makefile for the reason.

Other Answers:

Not sure if the correct solution but seemingly works:
add the second line in the Makefile:

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5 \
        opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs

I think the reason is you use make to compile, which makes caffe's python port only find libraries in this catalog. Maybe you use cmake to compile and it could work.
make clean
cd caffe-master
mkdir build
cd build
cmake ..
make all -j8
I hope I could help you!

More Issues: