C++11 在外部上下文中构建Caffe cpp_分类示例

C++11 在外部上下文中构建Caffe cpp_分类示例,c++11,gcc,protocol-buffers,caffe,C++11,Gcc,Protocol Buffers,Caffe,我已经在仅CPU_和仅GPU模式下从头配置并构建了Caffe(使用相应的示例和工具);并且对开箱即用的结果相当满意 然而,我正在启动我自己的项目,该项目源自cpp_分类示例,并且在构建独立于整个Caffe构建系统的项目时遇到了困难。因此,我回到了cpp_分类示例,并一直致力于将其构建为一个独立的示例(只是为了确保我没有遗漏任何内容),并且遇到了类似的错误 我与您分享我的构建错误输出和CMakeLists.txt的内容,希望成功提升cpp_分类示例的其他人能够提供指导 我已将生成错误缩小到以下范围

我已经在仅CPU_和仅GPU模式下从头配置并构建了Caffe(使用相应的示例和工具);并且对开箱即用的结果相当满意

然而,我正在启动我自己的项目,该项目源自cpp_分类示例,并且在构建独立于整个Caffe构建系统的项目时遇到了困难。因此,我回到了cpp_分类示例,并一直致力于将其构建为一个独立的示例(只是为了确保我没有遗漏任何内容),并且遇到了类似的错误

我与您分享我的构建错误输出和CMakeLists.txt的内容,希望成功提升cpp_分类示例的其他人能够提供指导

我已将生成错误缩小到以下范围:

Scanning dependencies of target cpp_classification
[ 50%] Building CXX object CMakeFiles/cpp_classification.dir/classification.cpp.o
[100%] Linking CXX executable cpp_classification
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `Classifier::Classifier(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&)':
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:62: 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*, caffe::Net<float> const*)'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:63: undefined reference to `caffe::Net<float>::CopyTrainedLayersFrom(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `Classifier::SetMean(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:124: undefined reference to `caffe::BlobProto::BlobProto()'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:129: undefined reference to `caffe::Blob<float>::FromProto(caffe::BlobProto const&, bool)'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:135: undefined reference to `caffe::Blob<float>::mutable_cpu_data()'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:124: undefined reference to `caffe::BlobProto::~BlobProto()'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:124: undefined reference to `caffe::BlobProto::~BlobProto()'
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `Classifier::Predict(cv::Mat const&)':
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:156: undefined reference to `caffe::Blob<float>::Reshape(int, int, int, int)'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:158: undefined reference to `caffe::Net<float>::Reshape()'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:165: undefined reference to `caffe::Net<float>::Forward(float*)'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:169: undefined reference to `caffe::Blob<float>::cpu_data() const'
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `Classifier::WrapInputLayer(std::vector<cv::Mat, std::allocator<cv::Mat> >*)':
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:184: undefined reference to `caffe::Blob<float>::mutable_cpu_data()'
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `Classifier::Preprocess(cv::Mat const&, std::vector<cv::Mat, std::allocator<cv::Mat> >*)':
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:227: undefined reference to `caffe::Blob<float>::cpu_data() const'
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `caffe::Caffe::set_mode(caffe::Caffe::Brew)':
/home/rudycazabon/caffe/distribute/include/caffe/common.hpp:148: undefined reference to `caffe::Caffe::Get()'
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `caffe::ReadProtoFromBinaryFileOrDie(char const*, google::protobuf::Message*)':
/home/rudycazabon/caffe/distribute/include/caffe/util/io.hpp:78: undefined reference to `caffe::ReadProtoFromBinaryFile(char const*, google::protobuf::Message*)'
collect2
试一试

set(CMAKE\u CXX\u FLAGS“${CMAKE\u CXX\u FLAGS}-D\u GLIBCXX\u USE\u cx11\u ABI=0”)

它告诉gcc将旧ABI用于

尝试

set(CMAKE\u CXX\u FLAGS“${CMAKE\u CXX\u FLAGS}-D\u GLIBCXX\u USE\u cx11\u ABI=0”)

它告诉gcc将旧ABI用于

cmake_minimum_required(VERSION 3.6)
project(cpp_classification)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(CAFFE_HOME ~/caffe/distribute)

find_package(OpenCV REQUIRED)
find_package(Caffe REQUIRED)
find_package(GTest REQUIRED)
find_package(glog REQUIRED)
find_package(Boost REQUIRED COMPONENTS system)
find_package(Protobuf REQUIRED)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES classification.cpp)

include_directories(${CAFFE_HOME}/include ${Boost_INCLUDE_DIRS} )
link_directories(${CAFFE_HOME}/lib ${Boost_LIBRARY_DIRS})

add_executable(cpp_classification
        ${SOURCE_FILES}
        ${GLOG_INCLUDE_DIR}
        ${Caffe_INCLUDE_DIR}
        ${Protobuf_INCLUDE_DIR})

TARGET_LINK_LIBRARIES(cpp_classification
        ${OpenCV_LIBS}
        ${Boost_LIBRARIES}
        ${GLOG_LIBRARY}
        ${CAFFE_LIBRARY}
        ${Protobuf_LIBRARY})