使用SSD目標檢測c++介面編譯問題解決記錄
阿新 • • 發佈:2018-12-14
本來SSD做測試的Python介面用起來也是比較方便的,但是如果部署整合的話,肯定要用c++環境,於是動手鼓搗了一下。
編譯用的cmake,寫的CMakeList.txt,期間碰到一些小問題,簡單記錄一下問題以及解決方法。
當然前提是你本地的caffe環境沒啥問題。各種依賴都安好了。。
1.error: ‘AnnotatedDatum’ has not been declared AnnotatedDatum* anno_datum);
/home/jiawenhao/ssd/caffe/include/caffe/util/io.hpp:192:40: error: ‘AnnotatedDatum_AnnotationType’ does not name a type const std::string& encoding, const AnnotatedDatum_AnnotationType type, ^ /home/jiawenhao/ssd/caffe/include/caffe/util/io.hpp:194:5: error: ‘AnnotatedDatum’ has not been declared AnnotatedDatum* anno_datum); ^ /home/jiawenhao/ssd/caffe/include/caffe/util/io.hpp:199:11: error: ‘AnnotatedDatum_AnnotationType’ does not name a type const AnnotatedDatum_AnnotationType type, const string& labeltype, ^ /home/jiawenhao/ssd/caffe/include/caffe/util/io.hpp:200:49: error: ‘AnnotatedDatum’ has not been declared const std::map<string, int>& name_to_label, AnnotatedDatum* anno_datum) {^ /home/jiawenhao/ssd/caffe/include/caffe/util/io.hpp:208:5: error: ‘AnnotatedDatum’ has not been declared AnnotatedDatum* anno_datum); ^ /home/jiawenhao/ssd/caffe/include/caffe/util/io.hpp:212:5: error: ‘AnnotatedDatum’ has not been declared AnnotatedDatum* anno_datum); ^ /home/jiawenhao/ssd/caffe/include/caffe/util/io.hpp:215:22: error: ‘AnnotatedDatum’ has not been declared const int width, AnnotatedDatum* anno_datum); ^ /home/jiawenhao/ssd/caffe/include/caffe/util/io.hpp:218:30: error: ‘LabelMap’ has not been declared const string& delimiter, LabelMap* map); ^ /home/jiawenhao/ssd/caffe/include/caffe/util/io.hpp:221:32: error: ‘LabelMap’ has not been declared bool include_background, LabelMap* map) { ^
caffe.pb.h這個檔案有問題。
在本地find了一下,
發現是有這個檔案的,
於是在/ssd/caffe/include/caffe下 mkdir一下 proto,然後把 caffe.bp.h 複製過來就好了。
如果沒有 caffe.pb.h可以用命令生成這個檔案,生成方法google一下就好了。。。。
2.連結庫的問題。錯誤提示說明用到了這個庫,但是程式沒找到。在CMakeList.txt裡填上 libflags.so即可 ,其他so庫同理。
/usr/bin/ld: CMakeFiles/ssd_detect.dir/ssd_detect.cpp.o: undefined reference to symbol '_ZN6google14FlagRegistererC1EPKcS2_S2_S2_PvS3_' /usr/lib/x86_64-linux-gnu/libgflags.so.2: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status CMakeFiles/ssd_detect.dir/build.make:102: recipe for target 'ssd_detect' failed make[2]: *** [ssd_detect] Error 1
這個是CMakeList.txt內容。 就是指定好include路徑,還有需要用到的各種庫的路徑。
cmake_minimum_required (VERSION 2.8) add_definitions(-std=c++11) project (ssd_detect) add_executable(ssd_detect ssd_detect.cpp) include_directories (/home/yourpath/ssd/caffe/include /usr/include /usr/local/include /usr/local/cuda/include ) target_link_libraries(ssd_detect /home/yourpath/ssd/caffe/build/lib/libcaffe.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_imgcodecs.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_videoio.so /usr/lib/x86_64-linux-gnu/libgflags.so /usr/lib/x86_64-linux-gnu/libglog.so /usr/lib/x86_64-linux-gnu/libprotobuf.so /usr/lib/x86_64-linux-gnu/libboost_system.so )