(1)去gcc官网下载源码包http://ftp.gnu.org/gnu/gcc/gcc-4.5.1/gcc-4.5.1.tar.bz2
(2)编译安装gcc之前需要先安装三个库,如果下面命令行不通,对应的都可以到官网下载:
$wgetftp://ftp.dti.ad.jp/pub/lang/gcc/infrastructure/gmp-4.3.2.tar.bz2
$wgetftp://ftp.dti.ad.jp/pub/lang/gcc/infrastructure/mpfr-2.4.2.tar.bz2
$wgetftp://ftp.dti.ad.jp/pub/lang/gcc/infrastructure/mpc-0.8.1.tar.gz
但是这种方法好像比较麻烦,mpfr依赖gmp的安装,mpc依赖前面两者的安装;
接着运行./configure--prefix=/afs/ihep.ac.cn/soft/common/gcc/gcc--enable-threads=posix--disable-multlib--enable-languages=c,c++,java--with-gmp-lib=gmpInstallDir/lib--with-gmp-include=gmpInstallDir/include--with-mpfr-lib=mpfrInstallDir/lib--with-mpfr-include=mpfrInstallDir/include--with-mpc-lib=mpcInstallDir/lib--with-mpc-include=mpcInstallDir/include
(3)所以我才用下面的方式通过apt-get install直接、分别进行安装:
在编译安装mpfr时出现错误,通过如下方式解决:
Availble mpfr
version for 13.04 is 3.1.1-1
. See packages.ubuntu.com for information.
You can install it by :
sudo apt-get install libmpfr-dev libmpfr-doc libmpfr4 libmpfr4-dbg
2. 32位系统:sudo apt-get install libc6-dev
期间它会自动安装libgmp-dev
随后的mpc也是通过apt-get install
libmpc-dev实现
通过apt-get install 默认的安装路径:/usr/bin /usr/lib /usr/share /usr/share/man
通过dpkg -L 软件名(如libgmp-dev)查看安装位置;
这些库的include目录、lib目录默认已经添加进环境变量;因此在编译安装gcc时不需要在./configure中显示说明
(4)进入gcc-4.5.1的目标目录,运行如下命令:(不是目标错误回报错https://gcc.gnu.org/bugzilla/show_bug.cgi?id=28298中Sebastian Forsman 2006-08-15 17:09:20 UTC 所说)
./configure--prefix=/afs/ihep.ac.cn/soft/common/gcc/gcc--enable-threads=posix--disable-multlib--enable-languages=c,c++,java
即可
(5)然后运行make、make check、make install命令
在make的时候出现错误:
/usr/include/stdc-predef.h:30:26: fatal error: bits/predefs.h:没有那个文件或目录
通过如下方法解决: 1. 确定你的系统是x86_64 GNU/Linux #uname -a 输出像:32 UTC 2008 x86_64 GNU/Linu 安装libc6-dev-i386:sudo apt-get install libc6-dev-i3863.输入sudo apt-get install
gcc-multilib 即可
./.libs/libgcj.so: undefined reference to `__cxa_call_unexpected”.
../.././libgcc/../gcc/config/i386/linux-unwind.h:138:17: error: field ‘info’ has incomplete type
通过打开linux-unwind.h,将138行由struct siginfo info;修改为siginfo_t info;
/usr/bin/ld: cannot find crti.o: 没有那个文件或目录
通过再网上找资料发现 export LIBRARY_PATH=/usr/lib/i386-linux-gnu中存在crti.o
To resolve, we need to modify the prims.cc file like below:--- libjava/prims.cc 2014-01-11 +++ libjava/prims.cc 2014-01-11 @@ -38,6 +38,14 @@ details. */
......... #endif
#ifndef DISABLE_GETENV_PROPERTIES +#ifdef __GLIBC__ +#define __NO_CTYPE 1 +#endif #include <ctype.h> #include <java-props.h> #define PROCESS_GCJ_PROPERTIES process_gcj_properties()
.........
(6)后续配置
查看原来的gcc所在的路径:which gcc
export PATH="/usr/local/gcc-4.5.1/bin:$PATH"
export LD_LIBRARY_PATH=/usr/local/gcc-4.5.1/lib:$LD_LIBRARY_PATH
通过gcc -v查看版本