如何将用g ++(Ubuntu)编译的库链接到用g ++(raspbian)编译的程序?

时间:2018-06-06 20:56:09

标签: c++11 docker g++ linker-errors raspbian

我有一个库(让我们称之为 libmylib.so ),这是一个使用运行Ubuntu 16的docker构建的。我想在一个程序中使用这个库(我们称之为< em> myapp )我希望在运行Raspbian的覆盆子Pi上编译。

编译时,我得到一个这种形式的输出日志:

[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

然后是一堆形式的错误:

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

从我在网上找到的内容来看,这似乎是因为我没有使用相同的编译器编译 libmylib.so myapp

我在两种情况下都使用g ++,但不是同一版本,就像我在两台设备上调用g ++ --version时所看到的那样。

来自我的码头:

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

来自我的树莓PI

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

这是一个完整的交易破坏者还是有办法让它发挥作用?

编辑: Here是我读到的,这让我觉得它是编译器版本问题。

Thisthis似乎是类似的错误,修补程序要添加到 myapp 的cmake中:

add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

哪个不起作用。

将此标志添加到 libmylib.so 的编译选项会将未定义的引用错误数从10减少到1.更确切地说:

undefined reference to `std::invalid_argument::invalid_argument(char const*)@GLIBCXX_3.4.21'

1 个答案:

答案 0 :(得分:0)

libmylib 编译为静态库,而不是以某种方式共享修复问题。

相关问题