最近由于需求的原因,需要把目前gcc-4.4.4升級(jí)到gcc-4.6.1,,考慮到有多臺(tái)的原因,,做了一個(gè)腳本自動(dòng)安裝結(jié)合批量工具分發(fā),。
一,、安裝環(huán)境
系統(tǒng)版本: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./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/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
然后執(zhí)行如下:
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/
//這一步很關(guān)鍵,,設(shè)置變量,,不設(shè)置后面會(huì)報(bào)錯(cuò)。
- make && make install
-
- 安裝完畢即可,!然后做一個(gè)鏈接就可以使用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++
三,、測(cè)試GCC
直接輸入gcc -v 可以查看到gcc 版本為4.6.1和相關(guān)的編譯參數(shù)就ok了!附上一個(gè)最簡(jiǎn)單的安裝腳本:
- #!/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
|