用caffe和Eigen编译C ++代码

时间:2017-06-12 09:34:54

标签: c++ opencv caffe eigen

我有C ++代码放在一些桌面目录中并且有一些调用caffe(使用opencv 3.1)和eigen。在编译代码时,我得到了对caffe方法的未定义引用。

我使用以下命令编译代码

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

我收到以下错误消息:

/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'

1 个答案:

答案 0 :(得分:2)

由于JovasaShai表示通过向链接器命令添加以下标志和caffelibrary路径来解决问题

  -L/path/to/caffe  -lcaffe