在BeagleBone上运行交叉编译的程序时,出现GLIBCXX_3.4.26未找到的错误。

9

我有以下的程序:

#include <iostream>
#include <sstream>
using namespace std;

int main()
{
    //ostringstream s;
    cout << "cpp test" << endl;
    return 0;
}

我使用交叉编译器在Ubuntu 20.04桌面版上构建它:

arm-linux-gnueabihf-g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/cpp_test.d" -MT"src/cpp_test.o" -o "src/cpp_test.o" "../src/cpp_test.cpp"
arm-linux-gnueabihf-g++  -o "cpp_test"  ./src/cpp_test.o

然后我将 cpp_test 复制到 BeagleBone Black Wireless 单板计算机上并执行它:

debian@beaglebone:~/c$ ./cpp_test 
cpp test
debian@beaglebone:~/c$ ldd cpp_test
    linux-vdso.so.1 (0xbee85000)
    libstdc++.so.6 => /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 (0xb6ea1000)
    libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb6e78000)
    libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6d7e000)
    libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6d03000)
    /lib/ld-linux-armhf.so.3 (0xb6fbe000)

现在我取消注释ostringstream s;这行代码,编译程序,将其复制到BeagleBone并执行:

debian@beaglebone:~/c$ ./cpp_test 
./cpp_test: /usr/lib/arm-linux-gnueabihf/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by ./cpp_test)
debian@beaglebone:~/c$ ldd cpp_test
./cpp_test: /usr/lib/arm-linux-gnueabihf/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by ./cpp_test)
    linux-vdso.so.1 (0xbefa6000)
    libstdc++.so.6 => /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 (0xb6e22000)
    libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6d28000)
    /lib/ld-linux-armhf.so.3 (0xb6f3f000)
    libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6cad000)
    libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb6c84000)

来自委员会的额外信息:

debian@beaglebone:/usr/lib/arm-linux-gnueabihf$ ls -l | grep libstdc++.so.6
lrwxrwxrwx  1 root root       19 Apr  6  2019 libstdc++.so.6 -> libstdc++.so.6.0.25
-rw-r--r--  1 root root  1019772 Apr  6  2019 libstdc++.so.6.0.25
debian@beaglebone:/usr/lib/arm-linux-gnueabihf$ uname -r
4.19.94-ti-r45
debian@beaglebone:/usr/lib/arm-linux-gnueabihf$ uname -a
Linux beaglebone 4.19.94-ti-r45 #1buster SMP PREEMPT Thu Jun 18 19:18:41 UTC 2020 armv7l GNU/Linux
debian@beaglebone:~$ strings /usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.25 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
...
GLIBCXX_3.4.24
GLIBCXX_3.4.25

主机提供的额外信息:

alex@alex-u20:~$ arm-linux-gnueabihf-g++ -v
使用内置规范。
COLLECT_GCC=arm-linux-gnueabihf-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabihf/9/lto-wrapper
目标:arm-linux-gnueabihf
配置:../src/configure -v --with-pkgversion='Ubuntu 9.3.0-10ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --without-target-system-zlib --enable-libpth-m2 --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --disable-werror --enable-multilib --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf- --includedir=/usr/arm-linux-gnueabihf/include
线程模型:posix
gcc 版本 9.3.0 (Ubuntu 9.3.0-10ubuntu1)
alex@alex-u20:/usr/lib/x86_64-linux-gnu$ strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 | grep GLIBCXX GLIBCXX_3.4 GLIBCXX_3.4.1 ... GLIBCXX_3.4.24 GLIBCXX_3.4.25 GLIBCXX_3.4.26 GLIBCXX_3.4.27 GLIBCXX_3.4.28

最后,这个程序在桌面上通过qemu运行:

alex@alex-u20:~/tmp/cpp_test/Debug$ qemu-arm-static -L /usr/arm-linux-gnueabihf/ cpp_test
cpp test

主机和BB板两台计算机都已经完全更新。


你可能使用了错误的工具链?检查一下你的GCC版本... - Asteroids With Wings
@AsteroidsWithWings:答案已更新,请查看“主机的附加信息”。 - Alex F
BeagleBone 上的 Ubuntu 版本是多少? - Asteroids With Wings
libstdc++.so.6.0.25GLIBCXX_3.4.26有什么区别? - Olaf Dietsche
@AsteroidsWithWings:Linux beaglebone 4.19.94-ti-r45 #1buster SMP PREEMPT Thu Jun 18 19:18:41 UTC 2020 armv7l GNU/Linux - Alex F
显示剩余4条评论
3个回答

21

GLIBCXX_3.4.26随着gcc-8一起提供。对我来说,安装gcc-8并升级libstdc++6有效。按照此处所示运行以下内容:

sudo apt update
sudo apt install wget gcc-8 unzip libssl1.0.0 software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt-get install --only-upgrade libstdc++6

1
有没有办法在不使用apt的情况下获取更新的libstdc++.so.6(适用于基于Yocto项目的发行版)?我已经在我的主机计算机上安装了gcc-9(Ubuntu WSL x86_64),但是在我的目标(armv7l)上,我有一个过时的版本的libstdc++.so.6 - Lincoln

8

虽然不是一个完整答案,但在我的Ubuntu 20.04系统上,我已安装包libstdc++6,其中包含libstdc++.so.6.0.28。

寻找符号

strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 | grep GLIBCXX

提供的内容:

...
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
...

所以,看起来版本 6.0.28 对应符号 3.4.28。

在您的情况下,您安装了 libstdc++.so.6.0.25,比 GLIBCXX_3.4.26 少一个版本。 因此,您必须要么升级 Beagle board,要么降级 dev 环境。


当前 (focal, 20.04) 的 libstdc++6 版本是 6.0.28。版本 6.0.25 包含于 bionic (18.04),其还包含 gcc-8。

因此,安装 gcc-8/g++-8 及其依赖项 (例如 libstdc++-8-dev) 可能会解决此问题。


谢谢,原因是正确的。我现在最简单的解决方案是切换到Linaro工具链。 - Alex F
@AlexF 另一个解决方案可能是创建一个带有Ubuntu 18.04或相应Debian版本的Docker容器。 - Olaf Dietsche

0

你可能没有Debian 11作为操作系统,Debian 10不支持3.4.26版本。升级到Debian 10后,我可以无错误地运行该程序。


1
你是指在“升级到Debian 11”之后,对吧? - Mark Jin
不好意思,我不记得了,MarkJin。 - Sahin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接