Linking caffe library and dependencies g++ make - c++

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.

Related

Libnoise don't want to compile: Cannot find -lnoise

I'm trying to use the Libnoise library and I keep get this error:
F:\PortableApps\Documents\Adventure³>g++ Compiled/*.o -o Adventure3 -L./Libs -static -lglew32 -lglfw3dll -lopengl32 -lfreetype -lnoise -static-libgcc-static-libstdc++ Resources/icon.res
f:/portableapps/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lnoise
collect2.exe: error: ld returned 1 exit status
I have the libnoise.lib in my Libs folder. I tried with -llibnoise instead, and I get:
F:\PortableApps\Documents\Adventure³>g++ Compiled/*.o -o Adventure3 -L./Libs -static -lglew32 -lglfw3dll -lopengl32 -lfreetype -llibnoise -static-libgcc -static-libstdc++ Resources/icon.res
Compiled/Generator.o:Generator.cpp:(.text+0x3d): undefined reference to `noise::module::Perlin::GetValue(double, double, double) const'
Compiled/Generator.o:Generator.cpp:(.text+0x8a): undefined reference to `noise::module::Perlin::Perlin()'
Compiled/Generator.o:Generator.cpp:(.text$_ZN5noise6module6PerlinD1Ev[__ZN5noise6module6PerlinD1Ev]+0xa): undefined reference to `vtable for noise::module::Perlin'
Compiled/Generator.o:Generator.cpp:(.text$_ZN5noise6module6PerlinD1Ev[__ZN5noise6module6PerlinD1Ev]+0x19): undefined reference to `noise::module::Module::~Module()'
collect2.exe: error: ld returned 1 exit status
I don't know how to manually compile the source, it always return me a WinMain#16 error, no matter what I try to make.
Now, I really don't know what to do...
Anyone have a solution?
-l option of gcc supposes that library got name starting with lib, so -lnoise would link libnoise.
Usually .lib is a n import library or static library. The problems related to import libraries described here: How do import libraries work and why doesn't MinGW need them?
In relation to libnoise: Netbeans C++ using MinGW and the libnoise library

undefined reference to boost library

I am getting static link errors to boost's non header only library. Let's solve it together:
The final binary is supposed to be built using libraries(libbasemainif.a for example) separately built as the higher layers. One of those layers, uses boost::filesystem.
Have a look at the simplified vesrion of g++ command:
g++ /mylis/1.a /mylibs/2.a
-L/myboost/Linux-x86_64/lib64
-Wl,-rpath,/myboost/Linux-x86_64/lib64 -Wl,-Bstatic
-lboost_thread-mt -lboost_system-mt -lboost_filesystem-mt -lboost_date_time-mt
-Wl,-Bdynamic
-Wl,-rpath,/myinstall/usr/local/lib64 -L/myinstall/usr/local/lib64 -Wl,
-Bstatic -lmyblahblah-static -Wl,-Bdynamic **-lbasemainif** -lbaseif -ldl -rdynamic -lz -lrt
-L/mypackage1/Linux-x86_64/debug/lib -L /mypackage2/18.1/Linux-x86_64/debug/lib -lpthread -Wl,-rpath,$ORIGIN/../lib64
and this is the error :
/blahblah/lib/libbasemainif.a(errorreportfile.o):
In function `boost::filesystem3::remove(boost::filesystem3::path const&, boost::system::error_code&)':
/myboost/Linux-x86_64/include/boost/filesystem/v3/operations.hpp:411:
undefined reference to boost::filesystem3::detail::remove(boost::filesystem3::path const&, boost::system::error_code*)'
collect2: ld returned 1 exit status
If I remove -Wl,-Bstatic the g++ command executes successfully.But this is not an option in production.
The libboost_filesystem.a is available. And all of the laibraries in every layer used boost from the same location.
Can you please tell me why I am getting this error? Thank you
You should pass to gcc library that implements function after the piece which references it. Something like: -lbasemainif -lboost_filesystem-mt. This is how gcc linker resolves dependencies.
Here is great detailed explanation.

Linking libcurl while cross compiling with mingw32 under Linux for Windows

I have compiled libcurl using mingw32 and am trying to link it with my program using mingw32 for a Windows system from my Linux machine.
I was outputted the files, libcurl-4.dll libcurl.a libcurl.la libcurl.lai.
I have included them in my mingw32 libs folder at: /usr/x86_64-w64-mingw32/lib
I was able to find a few other topics on linking with the libstdc++ and libgcc to take care dependency errors while executed but when trying to add libcurl.a it will not compile period.
I used the following:
$ x86_64-w64-mingw32-g++ main.cpp -o hello.exe -static-libgcc -static-libstdc++ -static "/usr/x86_64-w64-mingw32/lib/libcurl.a" -lpthread
However, I cannot not get it to use the libcurl.a and am continuing to receive these errors.
/tmp/ccIceRus.o:main.cpp:(.text+0xde): undefined reference to `__imp_curl_easy_init'
/tmp/ccIceRus.o:main.cpp:(.text+0x106): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x122): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x13e): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x159): undefined reference to `__imp_curl_easy_setopt'
/tmp/ccIceRus.o:main.cpp:(.text+0x169): undefined reference to `__imp_curl_easy_perform'
/tmp/ccIceRus.o:main.cpp:(.text+0x180): undefined reference to `__imp_curl_easy_strerror'
/tmp/ccIceRus.o:main.cpp:(.text+0x197): undefined reference to `__imp_curl_easy_cleanup'
/usr/bin/x86_64-w64-mingw32-ld: /tmp/ccIceRus.o: bad reloc address 0x80 in section `.xdata'
collect2: error: ld returned 1 exit status
What am I doing wrong?. I can not get past this. I know it has to be some stupid issue.
Thank you.
I was able to solve the question by specifying -DCURL_STATICLIB, as well as linking some other dependencies.
x86_64-w64-mingw32-g++ main.cpp -o hello.exe -DCURL_STATICLIB -static -lstdc++ -lgcc -lpthread -lcurl -lwldap32 -lws2_32

Undefined reference to 'dlsym' and 'dlopen'

I am compiling using arm-linux-gnueabi-g++ version 4.7.3.
I have the arm-linux-gnueabi libraries installed at location:
/usr/arm-linux-gnueabi/lib, it contains libdl.a, libdl.so, libdl.so.2,
and libdl-2.19.so.
libdl.so links to libdl.so.2 which links to libdl-2.19.so.
I am trying to link against the dl library (see command string below), but I always get the undefined reference errors.
arm-linux-gnueabi-g++ -I. -I../ -I../Comms/Linux -Wall -DLINUX -fpic -o ../../work/MyProgram main.o
-L../../work -L/usr/arm-linux-gnueabi/lib -lComms -lConsole -lUtilities -ldl
../../work/libUtilities.so: undefined reference to `dlsym'
../../work/libUtilities.so: undefined reference to `dlopen'
collect2: error: ld returned 1 exit status
If I compile using g++ 4.8.2 using the following commend then my program compiles, links, and executes fine.
g++ -I. -I../ -I../Comms/Linux -Wall -DLINUX -fpic -o ../../work/MyProgram main.o
-L../../work -lComms -lConsole -lUtilities -ldl
Obviously it can't find the libdl.so library; I thought that by adding the path to the location of the appropriate library by using the -L flag would fix the problem, but it didn't.
What am I missing with the ARM compiler command?
Well, I found the answer, I needed -Wl,--no-as-needed flag before the -ldl. I had run across this flag before I asked the question, but apparently mistyped it because it hadn't worked for me.
I don't understand why the flag is needed, but the code does finish linking now.
A SO user here says that it has to do with recent (2013 as of the user's post) versions of gcc linking to --as-needed.

Undefined reference to symbol, even though the library is linked

When linking a project I am working on, the linker gives the following errors:
/usr/bin/ld: ../Includes and Libs/lib/libsfml21rca.a(SoundFile.o): undefined reference to symbol 'sf_read_short##libsndfile.so.1.0'
/usr/bin/ld: note: 'sf_read_short##libsndfile.so.1.0' is defined in DSO /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libsndfile.so so try adding it to the linker command line
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libsndfile.so: could not read symbols: Invalid operation
The thing is, libsndfile.so is already linked before libsfml21rca.a, so I have no idea where the problem is.
I'm using Code::Blocks 10.05
Thanks for help in advance
EDIT:
Here is the linking command:
g++ -L"Includes and Libs/lib" -L"Includes and Libs/lib/raknet3_731" -L"Includes and Libs/lib/d3d_new/x86" -L"Includes and Libs/lib/ogg" -L"Includes and Libs/lib/sdl" -LBullet/lib -o (filename) ...(a whole lot of object files) -lGLEW -lglfw -lGL -lGLU -lpthread -lopenal -ljpeg -lfreetype -lsndfile -lXrandr -lsfml-system -lsfml-window -lsfml-audio ../Bullet/lib/LinearMath.lib ../Bullet/lib/BulletCollision.lib ../Bullet/lib/BulletDynamics.lib "../Includes and Libs/lib/raknet3_731/RakNetLibStaticDebug.lib" "../Includes and Libs/lib/libsfml21rca.a" ../../../../../../home/msabol/Desktop/SFML/sfml2st/sfmlVideo/sfmlVideo/bin/Release/libsfmlVideo.a ../../../../../../home/msabol/Desktop/SFML/sfmlVideo/bin/Release/libsfmlVideo.a
The linker only runs one pass over the library files. So if you have something in Library A that needs something in Library B, you need to have g++ objects... -llibA -llibB, if you use g++ objects... -llibB -llibA it will fail in the manner you show.
So, in your case, put the -lsndfile after "../Includes and Libs/lib/libsfml21rca.a".
(And whose idea was it to put spaces in a the "Includes and Libs" directory - not the best idea I've seen...)