Ubuntu 11.04安装GCC 4.6.1


首先下载相应的源代码:
ftp://ftp.dti.ad.jp/pub/lang/gcc/releases/gcc-4.6.1/
#下载 gcc-4.6.1.tar.bz2

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

Step 0:

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

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

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

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

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版本,需要做以下设置:

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/
保存后执行,更新共享库

1
$sudo ldconfig

相关内容