20.Ubuntu下安装GCC


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


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


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


  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值