g. 下载XZ: http://tukaani.org/xz/xz-5.0.3.tar.gz
h. 解压并安装xz
$ tar xzf xz*
$ cd xz*
$ ./configure --prefix=$HOME/local
$ make -j 8
$ make install
i. 配置环境变量
$ vi ~/.bashrc
添加:
export PATH=$HOME/local/bin:$PATH
export LD_LIBRARY_PATH=$HOME/local/lib:$LD_LIBRARY_PATH
j. 更新环境变量
source ~/.bashrc
3. 编译GCC
a. 下载GCC: http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-4.4.3/gcc-4.4.3.tar.bz2
b. 解压gcc,建立目标目录,我打算将GCC安装至 $HOME/local/gcc目录下,因此:
$ cd $HOME
$ bzcat gcc* | tar xvf -
$ cd local
$ mkdir gcc
$ cd gcc
$ ../../gcc-4.4.3//configure --prefix=$HOME/local/gcc
$ make -j 8
$ make install
m. 配置gcc的环境变量
$ vi ~/.bashrc
添加:
export PATH=$HOME/local/gcc/bin:$PATH
export LD_LIBRARY_PATH=$HOME/local/gcc/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$HOME/local/gcc/lib:$LD_LIBRARY_PATH
保存并更新:
source ~/.bashrc
c. 测试gcc版本
$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../../gcc-4.4.3//configure --prefix=/home/lixuezd/local/gcc --enable-shared --enable-threads=posix --enable-checking --with-zlib=/home/lixuezd/local/bin --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --build=x86_64-redhat-linux --with-gmp=/home/lixuezd/local --with-mpfr=/home/lixuezd/local --with-mpc=/home/lixuezd/local/ --enable-languages=c,c++
Thread model: posix
gcc version 4.4.3 (GCC)
4. bug-shooting
a. 采用--host=x86_64-redhat-linux参数,会提示这个错误:
make[2]: x86_64-redhat-linux-ar: Command not found
make[2]: *** [libiberty.a] Error 127
make[2]: Leaving directory `/home/lixuezd/local/gcc/libiberty'
make[1]: *** [all-libiberty] Error 2
make[1]: Leaving directory `/home/lixuezd/local/gcc'
make: *** [all] Error 2
解决方法:改用--build=x86_64-redhat-linux
b. GMP,MPFR,MPC缺失,提示错误忘了记下来了,解决方案是:
依次GMP->MPFR->MPC编译,编译参数层层递进:
GMP: $ ./configure --prefix=$HOME/local
MPFR: $ ./configure --with-gmp-include=$HOME/local/include --with-gmp-lib=$HOME/local/lib --
MPC: $ ./configure --prefix=$HOME/local --with-gmp=$HOME/local --with-mpfr=$HOME/local
c. 没有xz,提示同样没记下来,大致是找不到xz或lzma之类的,解决方案:
安装xz,并添加它的PATH到环境变量中
确认有没有xz,在终端下 输入xz即可,正确时显示:
xz: Compressed data cannot be written to a terminal
xz: Try `xz --help' for more information.
d. ./configure没有更新造成的
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最简单。
这里要提的就是,如果配置发生了更新,如果没有清空上一次的结果,可能会遇上这个问题。
f. java缺少必要的环境
configure: error: libXtst not found, required by java.awt.Robot
make[1]: *** [configure-target-libjava] Error 1
make[1]: Leaving directory `/home/lixuezd/local/gcc'
make: *** [all] Error 2
解决方案:要么去寻找还缺啥,补上它再去编译。因为我不用java,所以我去掉了它的编译:
--enable-languages=c,c++,(java去掉)
g. 64位需要两个Lib,所以添加环境变量时要用:
export LD_LIBRARY_PATH=$HOME/local/gcc/lib64:$LD_LIBRARY_PATHexport LD_LIBRARY_PATH=$HOME/local/gcc/lib:$LD_LIBRARY_PATH
不然会提示 glbc... libstdc++.so.6....什么的东西缺失吧,这个我也没记下来
