记录一下,免得每次到处找。安装GCC12.2.0,其他版本一样
源码下载地址:https://ftp.gnu.org/gnu/gcc/
备注:配置若有不明白的,多用 ./configure --help
查看
依赖可以在gcc源码目录下的contrib/download_prerequisites
文件中可以找到(head -40 contrib/download_prerequisites
)
yum install -y gcc gcc-c++ m4
下载地址: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
下载地址: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
下载地址: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
下载地址: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
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
安装后有提示:
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 variableduring execution- add LIBDIR to the 'LD_RUN_PATH' environment variableduring 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
make -j8
其中j
选项是指定并行度,因为我这台电脑8核,所以-j8
。--disable-multilib
,multilib貌似是指支持32位和64位,因为系统只有64位,因此disable
(如不加该选项,configure时会有提示)