centos上gcc升级

centos 6.8上yum install安装gcc默认版本为4.4.7,太低

准备升级

  • 下载高点版本,我这里下载 4.9.2
  • 解压tar -xvf gcc-4.9.2.tar.gz
  • 加载依赖项 ./contrib/download_prerequisites
坑来了,天坑

终端上一直卡在下面这步

1
2
3
4
5
6
7
8
9
10
[root@localhost gcc-4.9.2]# ./contrib/download_prerequisites
--2016-11-22 00:50:42-- ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.12.2.tar.bz2
=> “isl-0.12.2.tar.bz2”
Resolving gcc.gnu.org... 209.132.180.131
Connecting to gcc.gnu.org|209.132.180.131|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD (1) /pub/gcc/infrastructure ... done.
==> SIZE isl-0.12.2.tar.bz2 ... 1319434
==> PASV ...

这是因为ftp连接不上,需要的那些依赖项都下载不下来,vim ./contrib/download_prerequisites,文件部分内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Necessary to build GCC.
MPFR=mpfr-2.4.2
GMP=gmp-4.3.2
MPC=mpc-0.8.1
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPFR.tar.bz2 || exit 1
tar xjf $MPFR.tar.bz2 || exit 1
ln -sf $MPFR mpfr || exit 1
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$GMP.tar.bz2 || exit 1
tar xjf $GMP.tar.bz2 || exit 1
ln -sf $GMP gmp || exit 1
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPC.tar.gz || exit 1
tar xzf $MPC.tar.gz || exit 1
ln -sf $MPC mpc || exit 1
# Necessary to build GCC with the Graphite loop optimizations.
if [ "$GRAPHITE_LOOP_OPT" = "yes" ] ; then
ISL=isl-0.12.2
CLOOG=cloog-0.18.1
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$ISL.tar.bz2 || exit 1
tar xjf $ISL.tar.bz2 || exit 1
ln -sf $ISL isl || exit 1
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$CLOOG.tar.gz || exit 1
tar xzf $CLOOG.tar.gz || exit 1
ln -sf $CLOOG cloog || exit 1
fi

  • 还好浏览器可以翻墙,笨办法,先用浏览器把需要下载的依赖项下载下来
    下载的时候注意变量替换,比如:
    ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
  • 其它类似,都下载下来然后放到gcc-4.9.2目录下
  • 再把上述文件里面所有的wget命令都注释掉
  • 重新执行 ./contrib/download_prerequisites,问题解决了
  • 再执行 make(make的过程会很慢,等着吧), make install

打完收工