CentOS 下更新GCC版本至GCC 8.0.2

新买的服务器, GCC的版本还是4.8.5, 而GCC已经出到了8.2版本,这怎么能忍?

千万别更新!!! 血的教训!!! 折腾一天后我重装系统了!!!

更新前

1
2
3
4
5
[root@caoxl /]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)
Copyright (C) 2015 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.

更新后

1
2
3
4
5
[root@caoxl build]# gcc --version
gcc (GCC) 8.2.0
Copyright (C) 2018 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.

编译安装 GCC

https://ftp.gnu.org/gnu/gcc/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 下载
wget https://ftp.gnu.org/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz

// 解压
tar -zxvg gcc-8.2.0.tar.gz
cd gcc-8.2.0

// 安装依赖
./contrib/download_prerequisites

// 创建一个文件用来存放编译的文件,进入该文件
mkdir build && cd build

../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib

// 编译安装
make -j4 && make install

注意

    1. 动态库需要更新,因为GCC升级了,动态库也需要升级。
    1. gdb版本也需要升级的,否则无法调试

升级GDB版本

https://ftp.gnu.org/gnu/gdb/

这里选择和GCC相同版本: https://ftp.gnu.org/gnu/gdb/gdb-8.2.tar.gz

1
2
3
4
5
6
wget https://ftp.gnu.org/gnu/gdb/gdb-8.2.tar.gz
tar zxvf gdb-8.2.tar.gz
cd gdb-8.2
./configure
make
make install
1
2
3
4
5
6
[root@caoxl /]# gdb -v
GNU gdb (GDB) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

FAQ

tar (child): lbzip2: Cannot exec: No such file or directory

1
2
3
4
tar (child): lbzip2: Cannot exec: No such file or directory 
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

解决方法很简单,只要安装bzip2就行了,yum安装的命令如下:

1
yum -y install bzip2

Powered by Hexo and Hexo-theme-hiker

Copyright © 2017 - 2023 Keep It Simple And Stupid All Rights Reserved.

访客数 : | 访问量 :