Иван Гунько Иван Гунько - 1 year ago 273
C++ Question

Running simple C++ programm using Caffe

I am trying to run my simple program with caffe and i got a error

#include <iostream>
#include <caffe/caffe.hpp>
#include <memory>
using namespace std;
using namespace caffe;

int main(int argc, char** argv) {
shared_ptr<Net<float> > net_;

string file_name="it doesn't matter ";

net_.reset(new Net<float>(file_name, TEST));
// or just: Net<float> caffe_test_net(file_name, TEST);

It's built without problem, but when I run program Error:
symbol lookup error: /home/parrot/eclipse/workspace/Test_Caffe/Debug/Test_Caffe: undefined symbol: _ZN5caffe3NetIfEC1ERKSsNS_5PhaseEPKS1_

I noted that: problem appear when I use in code caffe::TEST or caffe::TRAIN. I think there are some problem connected to: caffe::Phase. So I can't create caffe::Net , becouse I can't use caffe::TEST.
When i use other class\function... etc from caffe library, There aren't produce this Error.

I use IDE: Eclipse to built project. Some report from console:

make all

Building file: ../src/Test_Caffe.cpp
Invoking: Cross G++ Compiler

g++ -I"/home/smilart/0_Intall/1 caffe-rc3/include/" -I/usr/local/cuda-7.5/include/ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Test_Caffe.d" -MT"src/Test_Caffe.o" -o "src/Test_Caffe.o" "../src/Test_Caffe.cpp"
Finished building: ../src/Test_Caffe.cpp

Building target: Test_Caffe
Invoking: Cross G++ Linker

g++ -L/usr/local/cuda/lib64/ -L"/home/smilart/0_Intall/1 caffe-rc3/build/lib/" -o "Test_Caffe" ./src/Test_Caffe.o -lboost_system -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lcudart -lcublas -lcurand -lboost_filesystem -lglog -lprotobuf -lcaffe
Finished building target: Test_Caffe

Answer Source

The directory /home/smilart/0_Intall/1 caffe-rc3/build/lib is not in the standard library search path that the dynamic loader (that loads dynamic libraries) looks in.

There are basiclaly four solutions to this problem:

  1. Install the libraries (and headers) into a system directory, one that the system loader looks for libraries in. Then rebuild.

  2. Add the directory /home/smilart/0_Intall/1 caffe-rc3/build/lib to the path for the loader to look in, by editing /etc/ld.so.conf, and run the ldconfig program.

  3. Modify the environment variable LD_LIBRARY_PATH to include the /home/smilart/0_Intall/1 caffe-rc3/build/lib. Few people recommend this solution though.

  4. Modify the build command so that the linker embeds the correct path to the libraries in the executable. This has to be done by adding -Wl,-rpath,/home/smilart/0_Intall/1 caffe-rc3/build/lib to the linker command line. This is done somewhere in the Eclipse project settings for the linker.

I recommend the last solution.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download