I’m trying to link a c++ program that uses several shared libraries from 3rd parties. Mainly, these libraries come from a github project called MBSim and I downloaded the latest daily build with all its binaries, libraries and headers, which I installed on /usr/local/mbsim-env
.
The most important libraries called are libmbsim
, libopenmbvcppinterface
, libfmatvec
and libboost_filesystem
(the last one comes with the MBSim distro).
I set up a simple code to test it and it compiles like a charm using
g++ main.cpp -m64 -g3 -std=c++11 -Wall -Wfatal-errors -Werror -Wno-unknown-pragmas -fopenmp `pkg-config --cflags mbsim` -I. -c -o main.o
The pkg-config
part calls, as you can wonder, the include directories and flags:
-DHAVE_ANSICSIGNAL -DHAVE_OPENMBVCPPINTERFACE -DHAVE_BOOST_FILE_LOCK -I/usr/local/mbsim-env/include -I/usr/include/x86_64-linux-gnu -I/usr/include/x86_64-linux-gnu/c++/5 -I/usr/local/include
My problems appear when I try to link the objects with the pre-compiled libraries with:
g++ system.o main.o -o teste -L/usr/local/mbsim-env/lib -lmbsim -lopenmbvcppinterface -lboost_system -lfmatvec -lm -Wl,-rpath,/usr/local/mbsim-env/lib
Edit: On the above command, I’ve tried to use pkg-config --libs
as well. The results remain the same.
First of all, the linker issues a warning that I’m linking against an older boost library:
/usr/bin/ld: warning: libboost_system.so.1.53.0, needed by /usr/local/mbsim-env/lib/libmbsim.so, may conflict with libboost_system.so.1.61.0
I’m aware of that, but I intentionally want to link against the old one because that’s the one that was used to compile the MBSim libraries.
After that, I got several undefined reference
warnings for almost every method that I call from MBSim:
system.cpp:59: undefined reference to MBSim::RigidBody::RigidBody(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
It seems to me that this error means that the target libraries don’t have the RigidBody
method implemented. Well, I know they do.
My first guess was that maybe the linker was looking at the wrong library path, so I set LD_LIBRARY_PATH=/usr/local/mbsim-env/lib
and added the -rpath
to the same folder. That didn’t help at all.
Some googling showed me that the problem could be compiling in 64bits and linking it against 32bits libs. I believe that’s not the case: I’ve done everything in Ubuntu 16.04 64bits and the MBSim libraries are also 64bits.
Could somebody point me out of this dead end?
Advertisement
Answer
Could it be that your 3rd party shared libraries are compiled using an older version of GCC? There was a new ABI introduced in GCC 5. It’s probably enabled by default on your platform. See https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html.
You could try switching to the older ABI, but that might require your other libraries to have been compiled with the old ABI also. You might also be able to switch ABIs for the 3rd party libraries explicitly.