Search code examples
c++opencvcaffeeigen

Compiling C++ code with caffe and Eigen


I have C++ code which placed in some desktop directory and have some calls to caffe (with opencv 3.1) and eigen. While compiling the code i am getting undefined references to caffe methods.

I am using following command to compile the code

g++ -I ../eigen-eigen-b9cd8366d4e8/ -I /path_to_caffe-rc5/include/  -I/usr/local/include/opencv  -I/usr/local/include/opencv2 -I /path_to_caffe-rc5/affe-rc5/distribute/include/ -L/usr/local/lib/ -g -o binary  test2.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_stitching -std=c++0x -lboost_system -lglog -DUSE_OPENCV -lopencv_imgcodecs -lgflags -std=c++11

I am getting following error message:

/tmp/cc4q0bWJ.o: In function `Detector::Detector(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/path_to_my file/test2.cpp:86: undefined reference to `caffe::Net<float>::Net(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, caffe::Phase, int, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const*)'
/path_to_my file/test2.cpp:87: undefined reference to `caffe::Net<float>::CopyTrainedLayersFrom(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/tmp/cc4q0bWJ.o: In function `Detector::Detect(cv::Mat const&)':
/path_to_my file/test2.cpp:105: undefined reference to `caffe::Blob<float>::Reshape(int, int, int, int)'
/path_to_my file/test2.cpp:107: undefined reference to `caffe::Net<float>::Reshape()'
/path_to_my file/test2.cpp:114: undefined reference to `caffe::Net<float>::Forward(float*)'
/path_to_my file/test2.cpp:118: undefined reference to `caffe::Blob<float>::cpu_data() const'

Solution

  • As Jovasa and Shai said the problem was solved with adding following flag and caffelibrary path to linker command

      -L/path/to/caffe  -lcaffe