升级g++详细步骤

1、下载gcc源码

对于只支持C++语言的编译,无需下载全代码包。可以只下载core源码和相应语言的源码包。

wget ftp://ftp.dti.ad.jp/pub/lang/gcc/releases/gcc-4.6.2/gcc-core-4.6.2.tar.bz2

wget ftp://ftp.dti.ad.jp/pub/lang/gcc/releases/gcc-4.6.2/gcc-g++-4.6.2.tar.bz2

2、解压到同一个目录

tar -jxvf gcc-core-4.6.2.tar.bz2

tar -jxvf gcc-g++-4.6.2.tar.bz2


源码将被加压到gcc-4.6.2目录中。

3、尝试./configure

cd gcc-4.6.2

./configure

报错如下:

configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.

4、安装 GMP,MPFR和MPC

4.1、下载源码

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2

4.2、安装

解压

./configure

make

make install

注意安装顺序:首先安装GMP,其次安装MPFR,最后安装MPC。

5、编译G++

./configure

make

然后是漫长的等待,中间会报出很多警告:

warning: duplicate `const'
不用管它。继续等待。在我的虚拟机上大概跑了近两个小时。幸亏不是编译gcc全语言包。

6、安装验证

make install

使用 gcc -v 查看,顺利升级到4.6.2。大笑




你可能感兴趣的:(c,虚拟机,gcc,语言)