CentOS GCC升級相關教程

來源:互聯網
上載者:User

最近由於需求的原因,需要把目前gcc-4.4.4升級到gcc-4.6.1,考慮到有多台的原因,做了一個指令碼自動安裝結合批量工具分發。

一、安裝環境
系統版本:centos6.0X64
原GCC版本:gcc-4.4.4
新GCC版本:gcc-4.6.1

二、正式安裝
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

  2. 如下:

  3. 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}

  4. wget http://ftp.gnu.org/gnu/gcc/gcc-4.6.1/gcc-4.6.1.tar.bz2 即可!

2、解壓安裝:安裝有先後順序:GMP、MPFR、MPC、GCC

 
  1. 安裝GMP: tar jxf gmp-4.3.2.tar.bz2 &&cd gmp-4.3.2/ ;./configure –prefix=/usr/local/gmp/ &&make &&make install

安裝MPFR:

 
  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

安裝MPC:

 
  1. 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:

 
  1. 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

然後執行如下:

 
  1. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/

//這一步很關鍵,設定變數,不設定後面會報錯。

 
  1. make && make install

  2. 安裝完畢即可!然後做一個連結就可以使用GCC了

  3. mkdir -p /data/backup/`date +%Y%m%d`

  4. mv /usr/bin/{gcc,g++} /data/backup/`date +%Y%m%d`

  5. 建立軟連結:

  6. ln -s /usr/local/gcc/bin/gcc /usr/bin/gcc

  7. ln -s /usr/local/gcc/bin/g++ /usr/bin/g++

三、測試GCC
直接輸入gcc -v 可以查看到gcc 版本為4.6.1和相關的編譯參數就ok了!附上一個最簡單的安裝指令碼:

 
  1. #!/bin/sh

  2. ##auto make install gcc

  3. ##2012-07-03

  4. tar jxf gmp-4.3.2.tar.bz2 &&cd gmp-4.3.2/ ;./configure –prefix=/usr/local/gmp/ &&make &&make install

  5. sleep 1

  6. 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

  7. 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

  8. 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/

  9. if

  10. [ $? -eq 0 ];then

  11. echo “This gcc configure is success”

  12. else

  13. echo “This gcc configure is failed”

  14. fi

  15. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/

  16. make && make install

  17. [ $? -eq 0 ]&&echo This is make install success


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.