下载需要的版本
官方网址 https://gcc.gnu.org/
选择对应的镜像站,可以根据自己的网络环境来选择https://gcc.gnu.org/mirrors.html
以http://ftp.ntua.gr/mirror/gnu/gcc/releases/gcc-11.2.0/这个镜像来举例,下载需要的文件
安装依赖的库
-
GMP
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2 tar jxf gmp-4.3.2.tar.bz2 cd gmp-4.3.2 ./configure make sudo make install
-
MPFR
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2 tar jxf mpfr-2.4.2.tar.bz2 cd mpfr-2.4.2 ./configure make sudo make install
-
MPC
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz tar zxf mpc-0.8.1.tar.gz cd mpc-0.8.1 ./configure make sudo make install
编译安装gcc
我下载的版本是gcc-5.1.0.tar.bz2
tar jxf gcc-5.1.0.tar.bz2
cd gcc-5.1.0
./configure
make
sudo make install
其它
-
指定GMP,MPFR,MPC路径
如果安装这些库时使用的不是默认的路径,可能会存在安装完成了,但是编译GCC仍然找不到这些库的情况,这时就存在两种解决方案
-
在配置gcc时指定库的路径,使用
./configure --with-gmp=<your directory> --with-mpfr=<your directory> --with-mpc=<your directory>
-
重新编译安装GMP,MPFR,MPC。使用默认路径(./configure时不指定–prefix)
-