1

I'm trying to add caffe to an existing project. I get 99 undefined reference errors, suggesting that it has something to do with linking libraries. The errors mention caffe, boost and google (relates to gflags or glog).

Linker command: (libcaffe is in /home/torcs/lib)

g++ main.o linuxspec.o -L/home/torcs/export/lib  -lopenal -lalut -lvorbisfile -L/usr/lib -L/home/torcs/lib  -lracescreens -lrobottools -lclient -lconfscreens -ltgf -ltgfclient -ltxml -lplibul -lraceengine -lmusicplayer -llearning -lplibjs -lplibssgaux -lplibssg -lplibsm -lplibsl -lplibsg -lplibul -lglut -lGLU -lGL -lpng -lz -ldl -lXrandr -lXrender -lXxf86vm -lXmu -lXi -lXt -lSM -lICE -lXext -lX11 -lm -lcaffe -lglog -o torcs-bin

Linker error (first 2 and final 2):

/home/torcs/export/lib/librobottools.so: undefined reference to `caffe::FillerParameter::_default_type_'
/home/torcs/export/lib/librobottools.so: undefined reference to `void caffe::caffe_gpu_set<float>(int, float, float*)'
...
/home/torcs/export/lib/librobottools.so: undefined reference to `caffe::NetStateRule::NetStateRule()'
/home/torcs/export/lib/librobottools.so: undefined reference to `caffe::Timer::MilliSeconds()'
collect2: error: ld returned 1 exit status

I added -lcaffe and tried libcaffe.a and libcaffe.so separately but the number of errors is not decreasing as I add libraries. If I misspel -lcaff it says cannot find libcaffe, which it doesn't do otherwise, so the lib is included correctly I guess.

I read up on linker order (windows background) and found that the symbols only get added if they are on the required symbols list. More specific libs should be last, dependent libs should be first. I figured that if I only add lcaffe at the end, the unrecognized symbol list should be populated, and at least the caffe symbols would be recognized, and maybe replaced by other dependencies. But that doesn't happen.

I tried to find whether libcaffe supplies the references. For the final undefined reference (caffe::Timer::MilliSeconds()), nm libcaffe.a finds:

0000000000188090 T _ZN5caffe5Timer12MilliSecondsEv
0000000000187910 T _ZN5caffe8CPUTimer12MilliSecondsEv

Which suggest the reference is in the lib. But the undefined reference error doesn't go away.

I also tried adding boost libs and glog, didn't help.

Edit. There is some additional weird behaviour going on. I think it is unrelated, but am not sure. The first time I build after a make clean I get an error about include <random>:

/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

This prevents the o files and librobottools.so from getting built. But if I make again, the c++11 error disappears, this lib does get build, and I see the 99 undefined reference errors.

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
benk
  • 377
  • 1
  • 4
  • 13
  • To get help with a failing linkage you must at least post the failing linker command, and the errors that follow from it, verbatim from the build output. Add this information in the body of your question. – Mike Kinghan Apr 04 '16 at 15:34
  • Thanks, I put it in the question. – benk Apr 04 '16 at 17:09
  • `librobottools` wants symbols from `libcaffe` but your linkage order appears correct to provide them. What is the actual filename of `libcaffe` in `/home/torcs/lib`? Are there any linker diagnostics about incompatible libraries skipped? Is there any other `libcaffe` in `/home/torcs/export/lib`, or even `/usr/lib`? – Mike Kinghan Apr 04 '16 at 18:26
  • (1) I have tried both `libcaffe.a` and `libcaffe.so` separately. Both produce the same errors. (2) No mention of incompatible libraries skipped, immediately after the command the linker errors appear. (3) I have found no other `libcaffe` files that might conflict with the one I want to link to. – benk Apr 04 '16 at 18:51
  • I added a build quirk to the post. – benk Apr 04 '16 at 19:07
  • Re (1) I wanted to know what the complete filename of `libcaffe` in `/home/torcs/lib` actually *is*. Are you saying there is both a `libcaffe.a` and `libcaffe.so` with exactly those names? Re. the build quirk. Do `make clean`. Add `-std=c++11` to the C++ compiler flags (`CXXFLAGS`), then rebuild, (Though it's a bug in the makefile that it gets passed this second time around.) Was your `libcaffe.a` also built with g++ 4.8, or some other version, or did you get it somewhere pre-built? – Mike Kinghan Apr 05 '16 at 17:25
  • Yes that is what I'm saying. I built caffe on the same machine, and that generated `libcaffe.a` and `libcaffe.so`. So I assume it's built with the same g++ 4.8 (haven't checked.) I did do `make clean`, and `-std=c++11` was already added to the flags. Btw, I found this build quirk is unrelated to the errors. I commented all c++ 11 stuff out, it skipped the c++11 error, and the same 99 undefined references showed up. – benk Apr 05 '16 at 18:21
  • @MikeKinghan I found that caffe is usually linked via CMake. So I'm trying to build my project using CMake. I almost succeeded, but ran into another linker error :( [question](http://stackoverflow.com/questions/36457998/c-gl-linker-undefined-reference). Maybe this one is solvable. – benk Apr 06 '16 at 17:21

0 Answers0