I am trying to install CAFFE in ubuntu 14.04 (no-gpu option) with OpenCV 3.0. I am getting the following linker error:
Linking CXX executable convert_imageset
cd /home/swami/packages_local/caffe/build/tools && /usr/bin/cmake -E cmake_link_script CMakeFiles/convert_imageset.bin.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC CMakeFiles/convert_imageset.bin.dir/convert_imageset.cpp.o -o convert_imageset -rdynamic ../lib/libcaffe.so ../src/caffe/proto/libproto.so -lprotobuf -llapack_atlas -lcblas -latlas -lboost_system -lboost_thread -lpthread -lpthread -lgflags -lglog -lhdf5_hl -lhdf5 -lleveldb -lsnappy -llmdb /usr/local/lib/libopencv_highgui.so.3.0.0 /usr/local/lib/libopencv_imgproc.so.3.0.0 /usr/local/lib/libopencv_core.so.3.0.0 -Wl,-rpath,/home/swami/packages_local/caffe/build/lib:/home/swami/packages_local/caffe/build/src/caffe/proto:/usr/local/lib: -Wl,-rpath-link,/usr/local/lib
../lib/libcaffe.so: undefined reference to cv::imread(cv::String const&, int)'
collect2: error: ld returned 1 exit status
make[2]: *** [tools/compute_image_mean] Error 1
make[2]: Leaving directory/home/swami/packages_local/caffe/build'
make[1]: ** [tools/CMakeFiles/compute_image_mean.bin.dir/all] Error 2
make[1]: ** Waiting for unfinished jobs....
../lib/libcaffe.so: undefined reference to cv::imread(cv::String const&, int)'
collect2: error: ld returned 1 exit status
make[2]: *** [tools/convert_imageset] Error 1
make[2]: Leaving directory/home/swami/packages_local/caffe/build'
make[1]: *** [tools/CMakeFiles/convert_imageset.bin.dir/all] Error 2
Has anyone come across this problem and can help me with this ?
this is probably because imread was moved to opencv_imgcodecs. Try to add -lopencv_imgcodecs to linker flags
Thanks! I found that 'pkg-config --cflags opencv' was not producing the output it should produce so I went ahead and installed the stable OpenCV (2.4-10) as opposed to the beta OpenCV 3.0. When I recompiled caffe with that I did not get any errors.
@swamiviv Yup!! re-install OpenCv2.4-10 will solve this problem.. :-)
I tried on my machine.
I added -lopencv_imgcodecs to my make file and it solved the issue for me.
Thanks!!!
how to add -lopencv_imgcodecs to make file??
You can add opencv_imgcodecs to 'Makefile'
how to add that to the make file? what did you write into the makefile?
@Mohammad-Mahdi
open your Makefile with some text editor, locate line 164 (in my case), add opencv_imgcodecs behind.
LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb boost_system hdf5_hl hdf5 m \
opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
I added opencv_imgcodecs to 'Makefile' but it didn't help.
@shubhamgoel27 there is opencv_imgcodecs in my Makefile already, and after I delete opencv_imgcodecs then I make pycaffe successfully.
I encounter with this issue and solved by removing # before pkg-config line(108). I will write some Makefile lines that runs for me without any error
uncomment line 11: USE_OPENCV := 1
uncomment line 21: OPENCV_VERSION := 3
uncomment line 108: USE_PKG_CONFIG := 1
but one thing that you must consider is that when you change Makefile, you must try below commands again(in my case I forgot to uncomment line 11 and after realized that I change my Makefile and test again by make test command but it not worked for me, because I have to make everything again so try below command first)
make clean
make all (if you want to do that faster then you use make all -j3 )
and test again with below commands
make test (or make test -j3)
where is the Makefile i cant find this file
where is the Makefile i cant find this file
Is it here? https://github.com/BVLC/caffe/blob/master/Makefile
Most helpful comment
@Mohammad-Mahdi
open your Makefile with some text editor, locate line 164 (in my case), add opencv_imgcodecs behind.