编译安装GCC
记录一下,免得每次到处找。安装GCC12.2.0,其他版本一样
源码下载地址:https://ftp.gnu.org/gnu/gcc/
备注:配置若有不明白的,多用 ./configure --help
查看
1 依赖安装
依赖可以在gcc源码目录下的contrib/download_prerequisites
文件中可以找到(head -40 contrib/download_prerequisites
)
1.0 gcc
yum install -y gcc gcc-c++ m4
1.1 gmp
下载地址:ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2
tar -jxf gmp-6.2.1.tar.bz2
cd gmp-6.2.1
./configure --prefix=/opt/local/gmp-6.2.1
make -j8
make install
1.2 isl
下载地址:ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.24.tar.bz2
tar -jxf isl-0.24.tar.bz2
cd isl-0.24
./configure --help
./configure --prefix=/opt/local/isl-0.24 --with-gmp-prefix=/opt/local/gmp-6.2.1
make -j8
make install
1.3 mpfr
下载地址:ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-4.1.0.tar.bz2
tar -jxf mpfr-4.1.0.tar.bz2
cd mpfr-4.1.0
./configure --prefix=/opt/local/mpfr-4.1.0 --with-gmp=/opt/local/gmp-6.2.1
make -j8
make install
1.4 mpc
下载地址:ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.2.1.tar.gz
tar -zxf mpc-1.2.1.tar.gz
cd mpc-1.2.1
./configure --prefix=/opt/local/mpc-1.2.1 --with-gmp=/opt/local/gmp-6.2.1 --with-mpfr=/opt/local/mpfr-4.1.0
make -j8
make install
2 编译安装GCC
export LD_LIBRARY_PATH=/opt/local/gmp-6.2.1/lib:/opt/local/mpfr-4.1.0/lib:/opt/local/mpc-1.2.1/lib:/opt/local/isl-0.24/lib:$LD_LIBRARY_PATH
tar -xf gcc-12.2.0.tar.xz
cd gcc-12.2.0
./configure --prefix=/opt/local/gcc-12.2.0 --with-gmp=/opt/local/gmp-6.2.1 --with-mpfr=/opt/local/mpfr-4.1.0 --with-mpc=/opt/local/mpc-1.2.1 --with-isl=/opt/local/isl-0.24 --disable-multilib
make -j8
make install
3 使用
安装后有提示:
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the 'LD_RUN_PATH' environment variable
during linking
- use the '-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to '/etc/ld.so.conf'
可以选择加入环境变量
export LD_LIBRARY_PATH=/opt/local/gmp-6.2.1/lib:/opt/local/mpfr-4.1.0/lib:/opt/local/mpc-1.2.1/lib:/opt/local/isl-0.24/lib:/opt/local/gcc-12.2.0/lib64:$LD_LIBRARY_PATH
export PATH=/opt/local/gcc-12.2.0/bin:$PATH
4 其他
make -j8
其中j
选项是指定并行度,因为我这台电脑8核,所以-j8
。- gcc的
--disable-multilib
,multilib貌似是指支持32位和64位,因为系统只有64位,因此disable
(如不加该选项,configure时会有提示) - 其他观察:原系统gcc是4.4.7版本的,编译的时候貌似会有三轮:一是使用系统自带gcc编译一个预生成版本;二是使用预生成版本再来重新编译成最终版;三是使用最终版再编译部分模块。以上只是观察到的现象及猜测,未深究。