Ubuntu 11.04安装GCC 4.6.1

来源:互联网 发布:姚明nba数据 编辑:程序博客网 时间:2024/06/04 20:08

 

转自:http://www.linuxidc.com/Linux/2011-07/39375.htm 偶尔看到的一篇文章,应该官方有相关说明,毕竟暂时没用到,没有再深究

 

首先下载相应的源代码:
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:
  
$sudo apt-get install build-essential
$sudo apt-get install zlibc
$sudo apt-get install zlib1g-dev

Step 1: 安装 gmp-4.3.2
  
#cd to src_dir
$./configure --prefix=/usr/local/gmp-4.3.2
$make
$sudo make install

Step 2: 安装 mpfr-2.4.2
  
#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
  
#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
  
$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版本,需要做以下设置:

$ 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:添加新版共享库
为了在编译软件时候,可以使用到最新的共享库
$sudo vim /etc/ld.so.conf.d/x86_64-linux-gnu.conf

添加下面内容
/usr/local/gcc-4.6.1/lib64/
保存后执行,更新共享库
$sudo ldconfig