1、用GNU上下载对应版本的源码包到本地,官网:http://ftp.gnu.org/gnu/gcc/
这里选用最新的包:
wget http://ftp.gnu.org/gnu/gcc/gcc-7.1.0/gcc-7.1.0.tar.gz
2、解压对应的包,然后进入到gcc-7.1.0目录下:
tar zxvf gcc-7.1.0.tar.gz
3、下载更新所需要的依赖包,执行:
./contrib/download_prerequisites
下载完成后,会看到新生成的文件
-rw-r--r-- 1 root root 2383840 Jun 12 12:34 gmp-6.1.0.tar.bz2
-rw-r--r-- 1 root root 1279284 Jun 12 12:34 mpfr-3.1.4.tar.bz2
-rw-r--r-- 1 root root 669925 Jun 12 12:34 mpc-1.0.3.tar.gz
-rw-r--r-- 1 root root 1626446 Jun 12 12:34 isl-0.16.1.tar.bz2
lrwxrwxrwx 1 root root 12 Jun 12 12:34 gmp -> ./gmp-6.1.0/
lrwxrwxrwx 1 root root 13 Jun 12 12:34 mpfr -> ./mpfr-3.1.4/
lrwxrwxrwx 1 root root 12 Jun 12 12:34 mpc -> ./mpc-1.0.3/
lrwxrwxrwx 1 root root 13 Jun 12 12:34 isl -> ./isl-0.16.1/
接下来安装对应的依赖包,依赖包可能存在一定依赖,请按照顺序进行安装,gmp->mpfr->mpc->ils。分别进入对应目录中,执行./configure ---> make ---> make install 即可。(这个顺序,亲测可行)
4、生成g++的makefile文件
./configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
5、编译
make
使用make -j4,采用多核优化提高速度
6、安装
make install
7、到此安装完毕,看到一下gcc,g++的版本
[[email protected] gcc-7.1.0]# gcc --version
gcc (GCC) 7.1.0
Copyright (C) 2017 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.
[[email protected] gcc-7.1.0]# g++ --version
g++ (GCC) 7.1.0
Copyright (C) 2017 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.
8、写个简单的Hello world测试一下
[[email protected] codes]# cat hello.cpp
#include <iostream>
int main()
{
std::cout<<"hello,world"<<std::endl;
return 0;
}
[[email protected] codes]#
[[email protected] codes]# g++ hello.cpp -std=c++14
[[email protected] codes]#
[[email protected] codes]# ./a.out
hello,world
[[email protected] codes]#
9、看来没问题,升级结束