ZQ博客

ZQ博客
学无止境-技术在于分享
  1. 首页
  2. Linux
  3. 正文

Linux上gcc升级GLIBCXX处理错误

2023年 6月 20日 2028点热度 0人点赞 0条评论

问题描述

在Linux中执行某些操作的时候缺少依赖

/lib64/libstdc++.so.6: version `GLIBCXX_3.4.33' not found 

问题分析

查了一下资料,可能是gcc版本太低了

查看一下当前版本

# 查找位置
find / -name "libstdc++.so.6*"

#centos
strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX
...
GLIBCXX_3.4.27

#ubuntu
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX
...
GLIBCXX_3.4.27
GLIBCXX_3.4.28
GLIBCXX_3.4.29
GLIBCXX_3.4.30

发现确实缺少了

解决方案1

从其他操作系统复制一个libstdc++.so.6过来,我这里报错的是centos7,从另一个Ubuntu22.04中复制一个过来,然后重新创建软连接:

$ ln -s  /usr/lib64/libstdc++.so.6.0.30 /usr/lib64/libstdc++.so.6

解决方案2

网上下载一个最新版的gcc

官网: http://ftp.gnu.org/gnu/gcc

# 下载 2018-10-30 04:28   123M    
wget  http://ftp.gnu.org/gnu/gcc/gcc-6.5.0/gcc-6.5.0.tar.gz

# 解压缩
 tar -zxf gcc-6.5.0.tar.gz

#编译安装 gcc:
cd gcc-6.5.0
./contrib/download_prerequisites

mkdir build
cd build
../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

# 这是一个漫长的过程:
make && make install

执行过程

[[root@localhost speech]# wget  http://ftp.gnu.org/gnu/gcc/gcc-6.5.0/gcc-6.5.0.tar.gz
--2023-05-31 15:07:14--  http://ftp.gnu.org/gnu/gcc/gcc-6.5.0/gcc-6.5.0.tar.gz
正在解析主机 ftp.gnu.org (ftp.gnu.org)... 209.51.188.20, 2001:470:142:3::b
正在连接 ftp.gnu.org (ftp.gnu.org)|209.51.188.20|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:129189622 (123M) [application/x-gzip]
正在保存至: “gcc-6.5.0.tar.gz”

100%[==================================================================================================================================================>] 129,189,622 4.04MB/s 用时 86s    

2023-05-31 15:08:40 (1.44 MB/s) - 已保存 “gcc-6.5.0.tar.gz” [129189622/129189622])

[root@localhost speech]# ls
audios  gcc-12.3.0  gcc-12.3.0.tar.gz  gcc-6.5.0.tar.gz  libstdc++.so.6  models  openjdk-20.0.1_linux-x64_bin.tar.gz  speech.jar
[root@localhost speech]# tar -zxf gcc-6.5.0.tar.gz 
[root@localhost speech]# cd gcc-6.5.0
[root@localhost gcc-6.5.0]# 
[root@localhost gcc-6.5.0]# ./contrib/download_prerequisites
--2023-05-31 16:03:37--  ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
           => “mpfr-2.4.2.tar.bz2”
正在解析主机 gcc.gnu.org (gcc.gnu.org)... 8.43.85.97, 2620:52:3:1:0:246e:9693:128c
正在连接 gcc.gnu.org (gcc.gnu.org)|8.43.85.97|:21... 已连接。
正在以 anonymous 登录 ... 登录成功!
==> SYST ... 完成。   ==> PWD ... 完成。
==> TYPE I ... 完成。 ==> CWD (1) /pub/gcc/infrastructure ... 完成。
==> SIZE mpfr-2.4.2.tar.bz2 ... 1077886
==> PASV ... 完成。   ==> RETR mpfr-2.4.2.tar.bz2 ... 完成。
长度:1077886 (1.0M) (非正式数据)

100%[==================================================================================================================================================>] 1,077,886   84.3KB/s 用时 14s    

2023-05-31 16:03:59 (72.7 KB/s) - “mpfr-2.4.2.tar.bz2” 已保存 [1077886]

--2023-05-31 16:03:59--  ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
           => “gmp-4.3.2.tar.bz2”
正在解析主机 gcc.gnu.org (gcc.gnu.org)... 8.43.85.97, 2620:52:3:1:0:246e:9693:128c
正在连接 gcc.gnu.org (gcc.gnu.org)|8.43.85.97|:21... 已连接。
正在以 anonymous 登录 ... 登录成功!
==> SYST ... 完成。   ==> PWD ... 完成。
==> TYPE I ... 完成。 ==> CWD (1) /pub/gcc/infrastructure ... 完成。
==> SIZE gmp-4.3.2.tar.bz2 ... 1897483
==> PASV ... 完成。   ==> RETR gmp-4.3.2.tar.bz2 ... 完成。
长度:1897483 (1.8M) (非正式数据)

100%[==================================================================================================================================================>] 1,897,483   93.3KB/s 用时 23s    

2023-05-31 16:04:30 (79.7 KB/s) - “gmp-4.3.2.tar.bz2” 已保存 [1897483]

--2023-05-31 16:04:30--  ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
           => “mpc-0.8.1.tar.gz”
正在解析主机 gcc.gnu.org (gcc.gnu.org)... 8.43.85.97, 2620:52:3:1:0:246e:9693:128c
正在连接 gcc.gnu.org (gcc.gnu.org)|8.43.85.97|:21... 已连接。
正在以 anonymous 登录 ... 登录成功!
==> SYST ... 完成。   ==> PWD ... 完成。
==> TYPE I ... 完成。 ==> CWD (1) /pub/gcc/infrastructure ... 完成。
==> SIZE mpc-0.8.1.tar.gz ... 544950
==> PASV ... 完成。   ==> RETR mpc-0.8.1.tar.gz ... 完成。
长度:544950 (532K) (非正式数据)

100%[==================================================================================================================================================>] 544,950     41.5KB/s 用时 16s    

2023-05-31 16:04:54 (33.2 KB/s) - “mpc-0.8.1.tar.gz” 已保存 [544950]

--2023-05-31 16:04:54--  ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.15.tar.bz2
           => “isl-0.15.tar.bz2”
正在解析主机 gcc.gnu.org (gcc.gnu.org)... 8.43.85.97, 2620:52:3:1:0:246e:9693:128c
正在连接 gcc.gnu.org (gcc.gnu.org)|8.43.85.97|:21... 已连接。
正在以 anonymous 登录 ... 登录成功!
==> SYST ... 完成。   ==> PWD ... 完成。
==> TYPE I ... 完成。 ==> CWD (1) /pub/gcc/infrastructure ... 完成。
==> SIZE isl-0.15.tar.bz2 ... 1574964
==> PASV ... 完成。   ==> RETR isl-0.15.tar.bz2 ... 完成。
长度:1574964 (1.5M) (非正式数据)

100%[==================================================================================================================================================>] 1,574,964    131KB/s 用时 14s    

2023-05-31 16:05:11 (111 KB/s) - “isl-0.15.tar.bz2” 已保存 [1574964]

[root@localhost gcc-6.5.0]# 
[root@localhost gcc-6.5.0]# mkdir build
[root@localhost gcc-6.5.0]# cd build
[root@localhost build]# ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
...
checking for ar... no
checking for ar... ar
checking for as... no
checking for as... as
checking for dlltool... no
checking for dlltool... no
checking for ld... no
checking for ld... ld
checking for lipo... no
checking for lipo... no
checking for nm... no
checking for nm... nm
checking for objcopy... no
checking for objcopy... objcopy
checking for objdump... no
checking for objdump... objdump
checking for ranlib... no
checking for ranlib... ranlib
checking for readelf... no
checking for readelf... readelf
checking for strip... no
checking for strip... strip
checking for windres... no
checking for windres... no
checking for windmc... no
checking for windmc... no
checking where to find the target ar... host tool
checking where to find the target as... host tool
checking where to find the target cc... just compiled
checking where to find the target c++... just compiled
checking where to find the target c++ for libstdc++... just compiled
checking where to find the target dlltool... host tool
checking where to find the target gcc... just compiled
checking where to find the target gcj... host tool
checking where to find the target gfortran... host tool
checking where to find the target gccgo... host tool
checking where to find the target ld... host tool
checking where to find the target lipo... host tool
checking where to find the target nm... host tool
checking where to find the target objcopy... host tool
checking where to find the target objdump... host tool
checking where to find the target ranlib... host tool
checking where to find the target readelf... host tool
checking where to find the target strip... host tool
checking where to find the target windres... host tool
checking where to find the target windmc... host tool
checking whether to enable maintainer-specific portions of Makefiles... no
configure: creating ./config.status
config.status: creating Makefile
[root@localhost build]# 

[root@localhost build]# make && make install
config.status: creating tune/Makefile
config.status: creating demos/Makefile
config.status: creating demos/calc/M

配置

$ cp /usr/local/lib64/libstdc++.so.6.0.22 /usr/lib64
$ cd /usr/lib64
$ rm -rf libstdc++.so.6
$ ln -s libstdc++.so.6.0.22 libstdc++.so.6

然后再次执行以下命令来查看是否包括 GLIBCXX_3.4.33

$ strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX
标签: gcc Linux
最后更新:2023年 6月 20日

zq

每天进步一点, 时间长了你会发现已经走了很远了

点赞
< 上一篇
下一篇 >
分类
  • ARM
  • Docker
  • java
  • Linux
  • OpenStack问题
  • springboot
  • SpringCloud
  • 前端开发
  • 技术分享
  • 数据库
  • 未分类
  • 版本控制
文章目录
  • 问题描述
  • 问题分析
  • 解决方案1
  • 解决方案2

COPYRIGHT ©2024 www.dowhere.com ALL RIGHTS RESERVED.and Theme Kratos