首先下載相應的源代碼:
ftp://ftp.dti.ad.jp/pub/lang/gcc/releases/gcc-4.6.1/
#下載 gcc-4.6.1.tar.bz2linux
ftp://ftp.dti.ad.jp/pub/lang/gcc/infrastructure/
#下載 gmp-4.3.2.tar.bz2 mpfr-2.4.2.tar.bz2 mpc-0.8.1.tar.gzc++
Step 0:vim
1 2 3 |
$sudo apt-get install build-essential $sudo apt-get install zlibc $sudo apt-get install zlib1g-dev |
Step 1: 安裝 gmp-4.3.2bash
1 2 3 4 |
#cd to src_dir $./configure --prefix=/usr/local/gmp-4.3.2 $make $sudo make install |
Step 2: 安裝 mpfr-2.4.2ui
1 2 3 4 |
#cd to src_dir $./configure --prefix=/usr/local/mpfr-2.4.2 --with-gmp=/usr/local/gmp-4.3.2 $make $sudo make install |
Step 3: 安裝 mpc-0.8.1code
1 2 3 4 |
#cd to src_dir $./configure --prefix=/usr/local/mpc-0.8.1 --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2 $make $sudo make install |
Step 4: 安裝 gcc-4.6.0get
1 2 3 4 5 |
$export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib #cd to src_dir $./configure --prefix=/usr/local/gcc-4.6.1 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2 --with-mpc=/usr/local/mpc-0.8.1 $make $sudo make install |
Step 5: 多版本支持
爲了讓Ubuntu支持多個gcc版本,須要作如下設置:it
1 2 3 4 |
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.5 40 $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc-4.6.1/bin/gcc 60 #選擇你須要的版本 $sudo update-alternatives --config gcc |
Step 6:添加新版共享庫
爲了在編譯軟件時候,可使用到最新的共享庫編譯
1 |
$sudo vim /etc/ld.so.conf.d/x86_64-linux-gnu.conf |
添加下面內容
/usr/local/gcc-4.6.1/lib64/
保存後執行,更新共享庫table
1 |
$sudo ldconfig |