首先我们介绍一种从零做起的编译方式,然后介绍一种相对简便的方法。
首先用系统中现存的编译器 按照顺序 编译上述的四个库,指定prefix为 $HOME 。如果库之间有依赖(例如MPFR依赖GMP),则需要在 configure 的时候指定 --with-SOME_LIB=$HOME 。
具体步骤如下:
$ ./configure --prefix=$HOME $ make $ make check $ make install $ ./configure --prefix=$HOME --with-gmp=$HOME $ make $ make check $ make install $ ./configure --prefix=$HOME --with-gmp=$HOME --with-mpfr=$HOME $ make $ make check $ make install $ ./configure --prefix=$HOME --with-gmp-prefix=$HOME $ make $ make check $ make install --with-gmp-prefix 而不是 --with-gmp ,否则会提示找不到gmp.h。 在 configure GCC的时候,如果提示找不到ISL库且错误信息如下:
checking for version 0.10 of ISL... no
checking for version 0.11 of ISL... no
checking for version 0.12 of ISL... no
checking for version 0.14 of ISL... no
configure: error: Unable to find a usable ISL. See config.log for details.
可以选择:
export LD_LIBRARY_PATH=$HOME/lib 将 $HOME/lib 加入共享库搜索路径。 进入gcc源码目录,开始正式编译GCC:
$ ./configure --prefix=$HOME --with-gmp=$HOME --with-mpfr=$HOME --with-mpc=$HOME --with-isl=$HOME --enable-languages=c,c++ --disable-multilib $ make -j4 $ make install 实际上我们无需手动去下载上述的库源代码,GCC提供了一个脚本,会下载并解压那些源代码,并且在编译GCC的过程中自动编译那些库。
下载并解压GCC源码后执行:
$ cd GCC_SOURCE # GCC_SOURCE代表你解压源代码的目录 $ ./contrib/download_prerequisites # 由脚本下载并解压必备库 $ cd #回到家目录 $ mkdir gcc-build $ cd gcc-build $ ../GCC_SOURCE/configure --prefix=$HOME --enable-languages=c,c++ --disable-multilib $ make -j4 $ make install 由于我们指定了 --prefix=$HOME ,所以GCC的可执行文件将被安装到 $HOME/bin ,请确保该目录位于 $PATH 中,然后执行 $ gcc --version 确认GCC版本。