1. 下载gcc和其依赖包,并按照以下顺序安装,其中--prefix可以根据自己的情况设置路径
1)下载:ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.1.tar.bz2
./configure --prefix=/usr/local/gmp make && make install
2)下载:http://ftp.gnu.org/gnu/mpfr/mpfr-3.1.2.tar.gz
./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp make && make install
3)下载:ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.2.tar.gz
./configure --prefix=/usr/local/mpc --with-gmp=/usr/local/gmp -with-mpfr=/usr/local/mpfr make && make install
4)下载:http://ftp.gnu.org/gnu/gcc/
./configure --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --with-mpc=/usr/local/mpc --prefix=/usr/local/gcc
make -j
make install
2. 可能遇到的问题
1)问题:
../../gcc-aarch64-sve-acle-branch/gcc/hwint.h:62:5: error: #error "Unable to find a suitable type for HOST_WIDE_INT" #error "Unable to find a suitable type for HOST_WIDE_INT" ^ In file included from ../../gcc-aarch64-sve-acle-branch/gcc/hash-table.h:243:0, from ../../gcc-aarch64-sve-acle-branch/gcc/coretypes.h:441, from ../../gcc-aarch64-sve-acle-branch/gcc/c/c-lang.c:23: ../../gcc-aarch64-sve-acle-branch/gcc/statistics.h:25:2: error: #error GATHER_STATISTICS must be defined #error GATHER_STATISTICS must be defined
解决办法:去除CPLUS_INCLUDE_PATH设置
export CPLUS_INCLUDE_PATH=
2)问题:
configure: error: `CC' has changed since the previous run: configure: former value: `x86_64-redhat-linux-gcc' configure: current value: `/home/lixuezd/local/gcc/./gcc/xgcc -B/home/lixuezd/local/gcc/./gcc/ -B/home/lixuezd/local/gcc/x86_64-redhat-linux/bin/ -B/home/lixuezd/local/gcc/x86_64-redhat-linux/lib/ -isystem /home/lixuezd/local/gcc/x86_64-redhat-linux/include -isystem /home/lixuezd/local/gcc/x86_64-redhat-linux/sys-include' configure: warning: ignoring whitespace changes in `CFLAGS' since the previous run: configure: former value: `-g -O2' configure: current value: `-g -O2 ' configure: error: `build_alias' has changed since the previous run: configure: former value: `x86_64-unknown-linux-gnu' configure: current value: `x86_64-redhat-linux' configure: error: in `/home/lixuezd/local/gcc/fixincludes': configure: error: changes in the environment can compromise the build configure: error: run `make distclean' and/or `rm ./config.cache' and start over make[1]: *** [configure-fixincludes] Error 1 make[1]: Leaving directory `/home/lixuezd/local/gcc' make: *** [all] Error 2
解决方法:
删掉gcc源码,重新建立gcc后再执行 ./configure .....,或者执行:make disclean和rm ./config.cache命令,我看着麻烦,还是 rm -fr gcc最简单。
这里要提的就是,如果配置发生了更新,如果没有清空上一次的结果,可能会遇上这个问题。