编译Caffe_SSD遇到的Bug及解决方法

cannot find #include “caffe/proto/caffe.pb.h

手动编译 caffe.prototxt , 在Caffe根目录下执行:

protoc src/caffe/proto/caffe.proto --cpp_out=.
mkdir include/caffe/proto
mv src/caffe/proto/caffe.pb.h include/caffe/proto

protoc版本问题

如果protoc版本为3.6.0,则需要手动编译caffe.prototxt,并在CMakeList及MakeFile中增加c++ 11支持

  • CMakeList

    1
    2
    3
    4
    5
    ---[ Flags

    if(UNIX OR APPLE)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -std=c++11")
    endif()if()
  • MakeFile

    1
    2
    3
    NVCCFLAGS += -std=c++11
    CXXFLAGS += -std=c++11
    LINKFLAGS += -std=c++11

json_parser_read.hpp:257:264: error: ‘type name’ declared as function returning an array escape

  • src/caffe/layers/下打开 detection_output_layer.cppdetection_output_layer.cu 注释掉:

    1
    write_json(ss,output);
  • include/caffe/layers/下打开detection_output_layer.hpp注释掉:

    1
    //#include <boost/property_tree/json_parser.hpp>

Undefined reference to google protobuf **

问题:

.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::io::CodedOutputStream::WriteVarint64ToArray(unsigned long long, unsigned char*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteInt64(int, long long, google::protobuf::io::CodedOutputStream*)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::UnknownFieldSet::AddVarint(int, unsigned long long)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::io::CodedOutputStream::VarintSize64(unsigned long long)'
.build_release/lib/libcaffe.so: undefined reference to `google::protobuf::io::CodedOutputStream::WriteVarint64(unsigned long long)'

解决办法:

  1. 执行pkg-config --libs protobuf,并将得到的结果加入到Makefile中LINKFLAGS 之后。如下所示,加入-pthread -lprotobuf -lpthread即可

    1
    2
    nr@linux ~ % pkg-config --libs protobuf
    -pthread -lprotobuf -lpthread