gcc升级到6.3.0版本

虚拟机环境信息:

[root@localhost /]# cat /etc/redhat-release

CentOS Linux release 7.3.1611 (Core)

[root@localhost /]# cat /proc/version

Linux version 3.10.0-514.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Nov 22 16:42:41 UTC 2016

可以看出gcc版本为4.8.5

GCC依赖于gmp 4.2+, mpfr 2.4+和mpc 0.8+,这里直接下载安装最新的版本。

安装gmp 6.1.2
wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.xz

tar xvf gmp-6.1.2.tar.xz
cd gmp-6.1.2
./configure --prefix=/usr/local/gmp
make -j20 && make install
(执行./configure --prefix=/usr/local/gmp时会出现错误 configure: error: could not find a working compiler。直接yum remove gcc 卸载然后 yum install gcc 重新安装再执行上述操作)

执行./configure --prefix=/usr/local/gmp 可能会出现如下错误
checking whether sscanf needs writable input… no
checking for struct pst_processor.psp_iticksperclktick… no
checking for suitable m4… configure: error: No usable m4 in $PATH or /usr/5bin (see config.log for reasons).

那就安装m4

yum install m4

安装成功后再次执行configure命令成功会显示如下界面

config.status: linking mpn/x86_64/coreihwl/gmp-mparam.h to gmp-mparam.h

config.status: executing libtool commands
configure: summary of build options:

Version: GNU MP 6.1.2
Host type: haswell-pc-linux-gnu
ABI: 64
Install prefix: /usr/local/gmp
Compiler: gcc -std=gnu99
Static libraries: yes
Shared libraries: yes

安装mpfr 3.1.5 mpfr依赖于gmp
wget http://www.mpfr.org/mpfr-current/mpfr-3.1.5.tar.gz

tar xvf mpfr-3.1.5.tar.gz
cd mpfr-3.1.5
./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp

make -j20 && make install

安装mpc 1.0.3 mpc依赖于gmp和mpfr
wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz

tar xvf mpc-1.0.3.tar.gz
cd mpc-1.0.3
./configure --prefix=/usr/local/mpc --with-gmp=/usr/local/gmp -with-mpfr=/usr/local/mpfr

make -j20 && make install

安装GCC 6.3.0
wget ftp://ftp.gnu.org/gnu/gcc/gcc-6.3.0/gcc-6.3.0.tar.gz
tar xvf gcc-6.3.0.tar.gz
cd gcc-6.3.0
./configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --with-mpc=/usr/local/mpc
make -j20&&make install

安装过程中可能会出现:
“checking for suffix of object files… configure: error: cannot compute suffix of object files: cannot compile

See `config.log’ for more details.

make[2]: *** [configure-stage1-target-libgcc] Error 1

make[2]: Leaving directory `/tmp/gcc-6.3.0’

make[1]: *** [stage1-bubble] Error 2

make[1]: Leaving directory `/tmp/gcc-6.3.0’

make: *** [bootstrap] Error 2

解决方法:
yum install m4
yum install gcc-c++

实际解决办法:编辑变量,把我们安装的gmp,mpfr,mpc加进去
vi /etc/ld.so .conf

添加部分:
/usr/local/lib #这个是默认系统的变量
/usr/local/gmp/lib
/usr/local/mpfr/lib
/usr/local/mpc/lib
添加保存后记得更新动态库的缓存:
ldconfig -v

更新后再去重新编译安装。

备份系统默认的gcc版本
mv /usr/bin/gcc /usr/bin/gcc-bak
mv /usr/bin/g++ /usr/bin/g+±bak
mv /usr/bin/c++ /usr/bin/c+±bak

创建新的gcc软连接
ln -sf /usr/local/gcc/bin/gcc /usr/bin/gcc
ln -sf /usr/local/gcc/bin/c++ /usr/bin/c++
ln -sf /usr/local/gcc/bin/g++ /usr/bin/g++
ln -sf /usr/local/gcc/lib64/libstdc++.so.6.0.22 /usr/lib64/libstdc++.so.6

查看gcc版本:
[root@localhost ~]# gcc --version
gcc (GCC) 6.3.0
Copyright © 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

或者

[root@localhost ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc/libexec/gcc/x86_64-pc-linux-gnu/6.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/usr/local/gcc --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --with-mpc=/usr/local/mpc
Thread model: posix
gcc version 6.3.0 (GCC)

升级到gcc7.0
sudo yum install centos-release-scl
sudo yum install devtoolset-7-gcc*
scl enable devtoolset-7 bash
which gcc
gcc --version

Ubuntu是一个基于Debian的开源操作系统,主要用于服务器和台式机,以其易用性和对开发者友好的支持而闻名。默认情况下,Ubuntu的软件包管理器会自动保持软件包的最新状态。如果你想手动将GCC(GNU Compiler Collection)升级到特定版本,比如10.2.1,你可以按照以下步骤操作: 1. **检查当前GCC版本**: 首先,确保你已经在Ubuntu上安装了GCC。在终端中输入以下命令: ``` sudo apt-cache policy gcc ``` 如果显示的是较旧的版本,那么你需要升级。 2. **添加PPA源** (如果可用) : 对于某些非官方版本GCC,可能需要添加第三方PPA(Personal Package Archive)。例如,对于10.2.1版本,Ubuntu没有直接提供,但你可以查找针对长期支持(LTS)版本的PPA,如 focal或eoan。添加PPA的命令类似这样: ``` sudo add-apt-repository ppa:ubuntu-toolchain-r/test ``` 3. **更新软件包列表**: 添加源后,运行: ``` sudo apt-get update ``` 4. **升级GCC**: 使用`sudo apt-get upgrade`,然后指定`gcc`: ``` sudo apt-get install gcc-10 g++-10 # 根据实际版本替换 ``` 5. **验证版本**: 安装完成后,你可以确认安装的新版本GCC: ``` gcc --version ``` 6. **切换默认编译器**: 有时可能还需要将新版本设置为默认编译器,可以通过编辑`/etc/bash.bashrc` 或 `/etc/environment` 文件来配置。 请注意,不是所有的系统都允许随意更改默认版本,尤其是生产环境。在执行这些步骤前,请确保备份数据并了解可能存在的风险。另外,由于Ubuntu Focal及后续版本已经包含了10系列的GCC,直接使用系统提供的版本可能会更为稳定。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值