将GCC安装在/usr/local/gcc-4.5.1目录下,支持C/C++和JAVA语言,其它选项参见GCC提供的帮助说明。
1)出现配置错误提示:
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /bin/sed
checking for gawk... gawk
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for gnatbind... no
checking for gnatmake... no
checking whether compiler driver understands Ada... no
checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
checking for objdir... .libs
checking for the correct version of gmp.h... no
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.
先开始安装GMP。
解压GMP的压缩包后,得到源代码目录gmp-5.0.1。
在该目录的同级目录下建立一个临时的编译目录,这里命名为temp。
$ tar -jxvf gmp-5.0.1.tar.bz2
$ cd gmp-5.0.1
$ mkdir temp
$ cd temp
然后开始配置安装选项,进入temp目录,输入以下命令进行配置:
$ ../configure --prefix=/usr/local/gmp-5.0.1
$ make
$ make install
再安装mpfr
$ tar -zxvf mpfr-3.1.2.tar.gz
$ cd mpfr-3.1.2
$ mkdir temp
$ cd temp
$ ../configure --prefix=/usr/local/mpfr-3.1.0 --with-gmp=/usr/local/gmp-5.0.1
$ make
$ make install
最后安装mpc
$ tar -zxvf mpc-1.0.2.tar.gz
$ cd mpc-1.0.2
$ mkdir temp
$ cd temp
$ ../configure --prefix=/usr/local/mpc-1.0.2 --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.0
$ make
$ make install
安装好这三个库之后,就可以正式开始安装gcc了。
当然了链接的时候,需要刚刚编译的3个lib。
$ vim /etc/profile
在最后一行加入:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-1.0.2/lib:/usr/local/gmp-5.0.1/lib:/usr/local/mpfr-3.1.0/lib
保存并退出
$ source /etc/profile
然后是典型的configure,make,install三步曲。
$ ./configure --prefix=/usr/local/gcc-4.5.1 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++
--with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.0 --with-mpc=/usr/local/mpc-1.0.2
$ make
$ make check(可选)
$ sudo make install