0

I have a library (let's call it libmylib.so) which was meant to be built using a docker running Ubuntu 16. I would like to use this library in a program (let's call it myapp) I wish to compile on my raspberry Pi running Raspbian.

When compiling, I get an output log of this form:

[25%] Building CXX object example1.cpp.o
[50%] Building CXX object example2.cpp.o
[75%] Building CXX object example3.cpp.o
[100%] Linking CXX executable target

And then a bunch of error of the form:

undefined reference to `VTT for std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
collect2: error: ld returned 1 exit status

From what I could find on the web, this seems due to the fact that I am not compiling libmylib.so and myapp with the same compiler.

I am using g++ in both cases, but not the same version, as can be seen when I call g++ --version on both device.

From my docker:

root@3ea34286736e:/usr/bin# g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.6) 5.4.0 20160609

From my raspberry PI

pi@raspberrypi:/usr/bin $ g++ --version
g++ (Raspbian 4.9.2-10+deb8u1) 4.9.2

Is this a complete deal breaker or is there a way to make it work?

EDIT: Here is what I read that makes me assume it is a compiler version problem.

This and this seemed to be similar errors, to which the fix was to add to the cmake of myapp:

add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

which did not work.

Adding this flag to the compile options of libmylib.so reduced the number of undefined reference errors from 10 to 1. More precisely:

undefined reference to `std::invalid_argument::invalid_argument(char const*)@GLIBCXX_3.4.21'
  • 1.) It appears to me from the linker errors that the immediate problem is libstdc++ mismatch 2.) Since raspberry pi is a different arch from x86, with a different instruction set, you shouldn't expect any object code from x86 to work on rpi unless it was specifically cross-compiled for that arch – Chris Beck Jun 07 '18 at 04:33
  • 1) Can you elaborate more? Googling libstdc++ mismatch tells me to apt-get install libstdc++6, but apparently I already have the most recent version. 2) I did cross-compile for the arm architecture. 3) So varying g++ versions should not be an issue? – Martin Leroux Jun 07 '18 at 13:17
  • Upgrading to a more modern version of gcc (e.g. 7.x.y) on both platforms should be prefered. Mixing libsdc++ versions is not desirable. As the last resort you can try copying libstdc++.so (the arm version of course) from your PC to the Pi and linking with that. Not guaranteed to work. – n. m. could be an AI Jun 07 '18 at 14:08
  • Apparently, by using a static version of the library, the problem disappeared. Thanks everyone. – Martin Leroux Jun 07 '18 at 17:08

1 Answers1

0

Compiling libmylib as a static library rather than shared somehow fixed the problem.