主页 > 电脑硬件  > 

20.Ubuntu下安装GCC


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


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


Ubuntu下安装GCC

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

查看官方安装指导

GCC版本查看,截止20240324,gcc最新的版本为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.

解决办法:

安装32位libc库文件./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


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


标签:

20.Ubuntu下安装GCC由讯客互联电脑硬件栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“20.Ubuntu下安装GCC