当前位置: 首页 > news >正文

20.Ubuntu下安装GCC

文章目录

  • Ubuntu下安装GCC
    • 查看官方安装指导
    • 错误
      • 缺少`gmp`库
      • 缺少`32`位开发库`libc`
      • g++: error: gengtype-lex.c: No such file or directory
      • reference


欢迎访问个人网络日志🌹🌹知行空间🌹🌹


Ubuntu下安装GCC

为了支持新的c++标准,需要安装新的GCC,安装步骤如下.

查看官方安装指导

GCC版本查看,截止20240324gcc最新的版本为13.2,支持到了c++23标准。

版本发布信息可以参考:GCC Releases查看。

安装指导参考的网页为:【GCC Installation Instructions】

  • 检查安装依赖,
  • 下载源码,可使用git命令克隆
git clone git://gcc.gnu.org/git/gcc.git
# 查看所有分支
git branch -a
# 查看所有标签
git tag -l

有时候,国内访问gcc放置代码的git仓库速度会很慢,这个时候可以从开源中国的码云平台上下载,

https://gitee.com/mirrors/gcc.git

这个是国内镜像,可以加速下载速度。

  • 下载源码后,切入源码目录,执行如下命令下载依赖
./contrib/download_prerequisites
  • 配置,可在源码仓库下新建build目录,然后切换到build目录下执行如下命令进行配置。
../configure --enable-languages=c,c++ --prefix=/usr/local/gcc-13.2.0 --host=x86_64-pc-linux-gnu --prefix=/home/xx/data/sw/gcc13 --disable-multilib

更多的配置参数可以参考页面https://gcc.gnu.org/install/configure.html

  • 安装
make -j4
sudo make install
  • 验证安装
/usr/local/gcc-13.2.0/bin/gcc --version
  • 设置环境变量
export PATH=$PATH:/usr/local/gcc-13.2.0/bin
  • 卸载
sudo rm -rf /usr/local/gcc-13.2.0

错误

缺少gmp

xx@xx-rob:~/data/code/gcc$ ./configure --enable-languages=c,c++ --prefix=/usr/local/gcc-13.2.

checking for the correct version of gmp.h... no
configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at

解决方法,先执行命令:

xx@xx-rob:~/data/code/gcc$ ./contrib/download_prerequisites

2024-03-21 22:31:18 URL:http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2 [2493916/2493916] -> "gmp-6.2.1.tar.bz2" [1]
2024-03-21 22:33:48 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-4.1.0.tar.bz2 [1747243/1747243] -> "mpfr-4.1.0.tar.bz2" [1]

2024-03-21 22:34:29 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.2.1.tar.gz [838731/838731] -> "mpc-1.2.1.tar.gz" [1]
2024-03-21 22:35:49 URL:http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.24.tar.bz2 [2261594/2261594] -> "isl-0.24.tar.bz2" [1]
gmp-6.2.1.tar.bz2: OK
mpfr-4.1.0.tar.bz2: OK
mpc-1.2.1.tar.gz: OK
isl-0.24.tar.bz2: OK
All prerequisites downloaded successfully.

缺少32位开发库libc

/usr/bin/ld: cannot find -lgcc
collect2: error: ld returned 1 exit status
configure: error: I suspect your system does not have 32-bit development libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to build a 64-bit-only compiler, rerun configure with --disable-multilib.

解决办法:

  • 安装32libc库文件
  • ./configure时使用参数--disable-multilib禁用编译32位平台上可以使用的库

g++: error: gengtype-lex.c: No such file or directory

编译过程中报错:

> and I found the Makefile in my objdir directory. I try `make -j4` and found
> g++: error: gengtype-lex.c: No such file or directory
> g++: fatal error: no input files
> Could you help me with this?

解决办法:

缺少flex库文件,手动安装:

sudo apt-get install flex

reference

1.https://www.spinics.net/lists/gcchelp/msg50998.html


欢迎访问个人网络日志🌹🌹知行空间🌹🌹


相关文章:

  • 1.7.2 python练习题15道
  • 【@changesets/cli】变更集实战教程
  • JavaEE之网络初识(网络中的一些基本概念)详解
  • iOS开发 - 转源码 - __weak问题解决
  • 【WPF应用7】 基本控件-Grid 布局的详解与示例
  • 【小尘送书-第十五期】Excel函数与公式应用大全for Excel 365 Excel
  • jvm高级面试题-2024
  • Vue3气泡卡片(Popover)
  • docker容器退出后数据丢失怎么恢复?
  • linux 命令行下的计算器
  • 也来混rt_thread了,碰到一个内存释放问题,顺便聊聊思路
  • 高阶SQL语句(二)
  • 电脑WinSxS文件夹太大,如何清理?分享四种方法
  • 【循环神经网络rnn】一篇文章讲透
  • C++入门:类和对象(上)
  • 【boost_search搜索引擎】2.正排索引和倒排索引
  • 37、Linux中Xsync数据同步备份工具
  • [BT]BUUCTF刷题第9天(3.27)
  • Golang-web开发好用的依赖库
  • 苹果与百度合作,将在iPhone 16中使用生成式AI
  • https://app.hackthebox.com/machines/Inject
  • Spring —— Spring简单的读取和存储对象 Ⅱ
  • 渗透测试之冰蝎实战
  • Mybatis、TKMybatis对比
  • Microsoft Office 2019(2022年10月批量许可版)图文教程
  • 《谷粒商城基础篇》分布式基础环境搭建
  • 哈希表题目:砖墙
  • Vue 3.0 选项 生命周期钩子
  • 【车载嵌入式开发】AutoSar架构入门介绍篇
  • 【计算机视觉 | 目标检测】DETR风格的目标检测框架解读