更新linux gcc版本到gcc 4.4.2
首先需要準備需要材料:gcc4.4.2版需要安裝gmp4.2.0+和mpfr2.3.0+,到GMP的網站(http://gmplib.org/)上下載gmp-4.3.1.tar.gz 和mprf的網站(http://www.mpfr.org/)上下載mpfr-2.4.2.tar.gz
1. 安裝gmp
# wget ftp://ftp.gmplib.org/pub/gmp-5.0.0/gmp-5.0.0.tar.bz2
# tar -zxvf gmp-4.3.2.tar.gz
# cd gmp-4.3.2
# ./configure
# make
# make check
這一步用來查看有沒有檔案不匹配或缺失,然後安裝:
# make install
2. 安裝mpfr
# wget http://www.mpfr.org/mpfr-current/mpfr-2.4.2.tar.gz
# tar -zxvf mpfr-2.4.2.tar.gz
# cd mpfr-2.4.2
配置:
# ./configure --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/local/lib
# make
# make check
接下來安裝:
# make install
打包成tar.gz, 需要xz(LZMA)支援; http://tukaani.org/xz/ 提供下載
# make dist
準備工作完成,以下是gcc的安裝與更新.
3. 編譯安裝gcc
從GCC官網(http://gcc.gnu.org/)下載資源gcc原始碼, 當前gcc版本為gcc-4.4.2.
# wget ftp://ftp.dti.ad.jp/pub/lang/gcc/releases/gcc-4.4.2/gcc-4.4.2.tar.gz
# tar xzvf gcc-4.4.2.tar.gz
建立目標目錄, 目標目錄是用來存放編譯結果的地方
# mkdir gcc-build
# cd gcc-build
配置gcc, 這裡只選擇了c,c++.
# ../gcc-4.4.2/configure --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++ --with-cpu=generic --disable-dssi --enable-plugin --prefix=/usr/local/gcc-4.4.2 --with-gmp=/usr/local --with-mpfr=/usr/local
編譯
# make
安裝, 需要管理員的許可權,如為普通使用者使用su 命令切換到root使用者.
# make install
至此,GCC 就安裝 完成了.
4. 環境設定
將gcc的標頭檔和庫檔案指向新的版本
cd $HOME
ls -a
sudo vi .bashrc
向其中添加以下語句。
GCCHOME=/usr/local/gcc-4.4.2
PATH=$GCCHOME/bin:$PATH
LD_LIBRARY_PATH=$GCCHOME/lib
export GCCHOME PATH LD_LIBRARY_PATH
5. 測試
重新引導,查看gcc版本
# source $HOME/.bashrc
# # which gcc
/usr/local/gcc-4.4.2/bin/gcc
會顯示gcc新的路徑為 /usr/local/gcc-4.4.2
# gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.4.2/configure --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++ --with-cpu=generic --disable-dssi --enable-plugin --prefix=/usr/local/gcc-4.4.2 --with-gmp=/usr/local --with-mpfr=/usr/local
Thread model: posix
gcc version 4.4.2 (GCC)
顯示gcc的版本為4.4.2