facebookarchive / caffe2

Caffe2 is a lightweight, modular, and scalable deep learning framework.
https://caffe2.ai
Apache License 2.0
8.42k stars 1.95k forks source link

Build Caffe2 C++ Example #1261

Open forever3000 opened 7 years ago

forever3000 commented 7 years ago

I tried to rebuild one Caffe2 C++ example as this link : https://github.com/leonardvandriel/caffe2_cpp_tutorial

But with simple g++ command as below: g++ pretrain.cc -I/home/vu/Desktop/Projects/caffe2 -I/home/vu/Desktop/Projects/caffe2/build -I/home/vu/Desktop/Projects/caffe2/third_party/eigen -lCaffe2_CPU -lprotobuf -lglog -lgflags -pthread --std=c++11pkg-config --cflags --libs opencv-L/home/vu/Desktop/Projects/caffe2/build/caffe2 then got this error: /tmp/ccZEKrOW.o: In functioncaffe2::(anonymous namespace)::Caffe2FlagParser_init_net::Caffe2FlagParser_init_net(std::string const&)': pretrain.cc:(.text+0x12a): undefined reference to bool caffe2::Caffe2FlagParser::Parse<std::string>(std::string const&, std::string*)' /tmp/ccZEKrOW.o: In functioncaffe2::(anonymous namespace)::Caffe2FlagParser_predict_net::Caffe2FlagParser_predict_net(std::string const&)': pretrain.cc:(.text+0x166): undefined reference to bool caffe2::Caffe2FlagParser::Parse<std::string>(std::string const&, std::string*)' /tmp/ccZEKrOW.o: In functioncaffe2::(anonymous namespace)::Caffe2FlagParser_image_file::Caffe2FlagParser_image_file(std::string const&)': pretrain.cc:(.text+0x1a2): undefined reference to bool caffe2::Caffe2FlagParser::Parse<std::string>(std::string const&, std::string*)' /tmp/ccZEKrOW.o: In functioncaffe2::(anonymous namespace)::Caffe2FlagParser_size_to_fit::Caffe2FlagParser_size_to_fit(std::string const&)': pretrain.cc:(.text+0x1de): undefined reference to bool caffe2::Caffe2FlagParser::Parse<int>(std::string const&, int*)' /tmp/ccZEKrOW.o: In function__static_initialization_and_destruction_0(int, int)': pretrain.cc:(.text+0x144f): undefined reference to caffe2::Caffe2FlagsRegistry()' pretrain.cc:(.text+0x154a): undefined reference tocaffe2::Caffe2FlagsRegistry()' pretrain.cc:(.text+0x1645): undefined reference to caffe2::Caffe2FlagsRegistry()' pretrain.cc:(.text+0x16fe): undefined reference tocaffe2::Caffe2FlagsRegistry()' /tmp/ccZEKrOW.o: In function caffe2::CPUContext::New(unsigned long)': pretrain.cc:(.text._ZN6caffe210CPUContext3NewEm[_ZN6caffe210CPUContext3NewEm]+0x32): undefined reference tocaffe2::FLAGS_caffe2_report_cpu_memory_usage' /tmp/ccZEKrOW.o: In function void caffe2::Tensor<caffe2::CPUContext>::Resize<std::vector<long, std::allocator<long> > >(std::vector<long, std::allocator<long> >)': pretrain.cc:(.text._ZN6caffe26TensorINS_10CPUContextEE6ResizeIISt6vectorIlSaIlEEEEEvDpT_[_ZN6caffe26TensorINS_10CPUContextEE6ResizeIISt6vectorIlSaIlEEEEEvDpT_]+0x92): undefined reference tocaffe2::FLAGS_caffe2_keep_on_shrink' pretrain.cc:(.text._ZN6caffe26TensorINS10CPUContextEE6ResizeIISt6vectorIlSaIlEEEEEvDpT[_ZN6caffe26TensorINS10CPUContextEE6ResizeIISt6vectorIlSaIlEEEEEvDpT]+0xaf): undefined reference to caffe2::FLAGS_caffe2_max_keep_on_shrink_memory' collect2: error: ld returned 1 exit status

Anybody is facing same problem. May I need to rebuild caffe2 to support above APIs. Thanks

leovandriel commented 6 years ago

The culprit seems to be -I/home/vu/Desktop/Projects/caffe2, which includes too broadly. Just removing that should resolve these build errors.

Also, you probably need to add -Iinclude, which includes headers from the caffe2_cpp_tutorial project. See the build alternatives section for more info.