因工作需要,要把目前gcc-4.4.4升级到gcc-4.6.1,考虑到有多台机器的原因,于是做了一个脚本自动安装结合批量工具分发。
一、安装环境
系统版本:centos6.0X64
原GCC版本:gcc-4.4.4
新GCC版本:gcc-4.6.1
二、正式安装
1、下载安装的源码:
需要下载的包:gcc-4.6.1.tar.bz2 gmp-4.3.2.tar.bz2 mpc-0.8.1.tar.gz mpfr-2.4.2.tar.bz2
下载地址:
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/{gmp-4.3.2.tar.bz2,mpc-0.8.1.tar.gz,mpfr-2.4.2.tar.bz2}
wget http://ftp.gnu.org/gnu/gcc/gcc-4.6.1/gcc-4.6.1.tar.bz2
2、解压安装:安装有先后顺序:GMP、MPFR、MPC、GCC
安装GMP: tar jxf gmp-4.3.2.tar.bz2 &&cd gmp-4.3.2/ ;./configure –prefix=/usr/local/gmp/ &&make &&make install
安装MPFR:
cd ../ ;tar jxf mpfr-2.4.2.tar.bz2 ;cd mpfr-2.4.2/ ;./configure –prefix=/usr/local/mpfr –with-gmp=/usr/local/gmp &&make &&make install
安装MPC:
cd ../ ;tar xzf mpc-0.8.1.tar.gz ;cd mpc-0.8.1 ;./configure –prefix=/usr/local/mpc –with-mpfr=/usr/local/mpfr –with-gmp=/usr/local/gmp &&make &&make install
安装GCC:
cd ../ ;tar jxf gcc-4.6.1.tar.bz2 ;cd gcc-4.6.1 ;./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 &&make install
然后执行如下:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/
//这一步很关键,设置变量,不设置后面会报错。
make && make install
安装完毕即可!然后做一个链接就可以使用GCC了
mkdir -p /data/backup/`date +%Y%m%d`
mv /usr/bin/{gcc,g++} /data/backup/`date +%Y%m%d`
新建软链接:
ln -s /usr/local/gcc/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc/bin/g++ /usr/bin/g++
三、测试GCC
直接输入gcc -v 可以查看到gcc 版本为4.6.1和相关的编译参数,就说明安装与配置是成功的。
附简单安装脚本,供朋友们学习参考:
#!/bin/sh
##auto make install gcc
##2012-07-03
tar jxf gmp-4.3.2.tar.bz2 &&cd gmp-4.3.2/ ;./configure –prefix=/usr/local/gmp/ &&make &&make install
sleep 1
cd ../ ;tar jxf mpfr-2.4.2.tar.bz2 ;cd mpfr-2.4.2/ ;./configure –prefix=/usr/local/mpfr –with-gmp=/usr/local/gmp &&make &&make install
cd ../ ;tar xzf mpc-0.8.1.tar.gz ;cd mpc-0.8.1 ;./configure –prefix=/usr/local/mpc –with-mpfr=/usr/local/mpfr –with-gmp=/usr/local/gmp &&make &&make install
cd ../ ;tar jxf gcc-4.6.1.tar.bz2 ;cd gcc-4.6.1 ;./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/
if
[ $? -eq 0 ];then
echo “This gcc configure is success”
else
echo “This gcc configure is failed”
fi
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/
make && make install
[ $? -eq 0 ]&&echo This is make install success