centOS 7升级gcc,gdb,cmake

centOS 7升级gcc,gdb,cmake

entOS自带的gcc为4.8版本,而使用yum也无法安装更高版本的gcc

  1. 获取gcc源代码

    获取gcc源代码并上传至虚拟机

解压gcc

[root@222 ~]# tar -xvf gcc-10.2.0.tar.gz

执行./configure/ 会报错,提示需要安装对应的依赖

configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.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
ftp://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.

本文以MPC:1.0.3 mpfr:3.1.5 gmp:6.1.2安装gcc10.2.0,对应的源代码地址为:

MPC : http://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz

GMP : http://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.xz

MPFR : http://ftp.gnu.org/gnu/mpfr/mpfr-3.1.5.tar.gz

安装GMP

[root@222 ~]# tar -xvf gmp-6.1.2.tar.gz
[root@222 ]# cd gmp-6.1.2/
[root@222 gmp-6.1.2]# ../gmp-6.1.2/configure --prefix=/usr/local/gmp-6.1.2
[root@222 gmp-6.1.2]# make && make install

安装MPFR

[root@222 ~]# tar -xvf mpfr-3.1.5.tar.gz
[root@222 ~]# cd mpfr-3.1.5/
[root@222 mpfr-3.1.5]# ./configure --prefix=/usr/local/mpfr-3.1.5 --with-gmp=/usr/local/gmp-6.1.2
[root@222 mpfr-3.1.5]# make && make install

安装MPC

[root@222 ~]# tar -xvf mpc-1.0.3.tar.gz
[root@222 ~]# cd mpc-1.0.3/
[root@222 mpc-1.0.3]# ./configure --prefix=/usr/local/mpc-1.0.3 --with-gmp=/usr/local/gmp-6.1.2--with-mpfr=/usr/local/mpfr-3.1.5
[root@222 mpc-1.0.3]# make && make install

安装gcc

[root@222 ~]# cd gcc-10.2.0/
[root@222 gcc-10.2.0]# mkdir tmp && cd tmp
[root@222 tmp]# ../configure --prefix=/usr/local/gcc-10.2.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-3.1.5 --with-mpc=/usr/local/mpc-1.0.3

[root@222 tmp]# make && make install

注:最后gcc编译安装的时间很长,可能需要1-2个小时,建议在时间和网络允许的情况下进行

安装完成还需要执行如下命令:

mv /usr/bin/gcc /usr/bin/gcc485
mv /usr/bin/g++ /usr/bin/g++485
mv /usr/bin/c++ /usr/bin/c++485
mv /usr/bin/cc /usr/bin/cc485
ln -s /usr/local/gcc-10.2.0/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-10.2.0/bin/g++ /usr/bin/g++
ln -s /usr/local/gcc-10.2.0/bin/c++ /usr/bin/c++
ln -s /usr/local/gcc-10.2.0/bin/gcc /usr/bin/cc
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
ln -s /usr/local/gcc-10.2.0/lib64/libstdc++.so.6.0.28 /usr/lib64/libstdc++.so.6

最后gcc -v 就可以发现gcc升级成功

中途报错可以查看这位大佬的文章 https://blog.csdn.net/Tsuki_jhsyi77/article/details/103111687

若本方法不行,也可以尝试这位大佬的方法 https://blog.csdn.net/b_ingram/article/details/121569398

gdb升级

官网:https://gcc.gnu.org/
下载镜像:https://gcc.gnu.org/mirrors.html
速度比较好的下载镜像:ftp://mirrors.ustc.edu.cn/gnu/
下载gdb-8.3.1.tar.gz;
建议在安装gcc前,先装gdb的升级,gdb的升级不能用太高版本的gcc编绎,或者在编绎时指定低版本的gcc。
本次成功编绎gdb的gcc版本是:gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)。
相关命令如下:
tar -xzvf gdb-8.3.1.tar.gz
cd gdb-8.3.1
如果需要指定编绎的gcc版本,可以用以CC指定具体的gcc,如下面的/usr/local/gcc/bin/gcc就是gcc的安装目录:
CC=/usr/local/gcc/bin/gcc ./configure
否则可以直接编绎:
./configure
make
make install
在安装前系统需要安装texinfo:yum install texinfo
如果之前系统没有安装gcc,先执行:
yum install gcc
yum install gcc-c++

cmake升级

https://blog.csdn.net/qq_19734597/article/details/104200371

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值