1、下载gcc
https://ftp.gnu.org/gnu/gcc/
2、下载依赖包
https://gcc.gnu.org/pub/gcc/infrastructure/
sudo apt install m4
3、安装依赖包
sudo tar -jxvf gmp-6.1.0.tar.bz2
sudo mkdir /usr/local/gmp-6.1.0
sudo ./configure --prefix=/usr/local/gmp-6.1.0/
sudo make
sudo make check
sudo make install
sudo tar -jxvf mpfr-3.1.4.tar.bz2
sudo mkdir /usr/local/mpfr-3.1.4
sudo ./configure --prefix=/usr/local/mpfr-3.1.4 --with-gmp=/usr/local/gmp-6.1.0
sudo make -j
sudo make check
sudo make install
sudo tar -zxvf mpc-1.0.3.tar.gz
sudo mkdir /usr/local/mpc-1.0.3
sudo ./configure --prefix=/usr/local/mpc-1.0.3 --with-gmp=/usr/local/gmp-6.1.0 --with-mpfr=/usr/local/mpfr-3.1.4
sudo make -j
sudo make check
sudo make install
sudo tar -jxvf isl-0.18.tar.bz2
sudo mkdir /usr/local/isl-0.18
sudo ./configure --prefix=/usr/local/isl-0.18 --with-gmp-prefix=/usr/local/gmp-6.1.0
sudo make -j
sudo make check
sudo make install
4:设置环境变量
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-1.0.3/lib:/usr/local/mpfr-3.1.4/lib:/usr/local/isl-0.18/lib:/usr/local/gmp-6.1.0/lib
5:编译gcc
tar -xvzf gcc-10.2.0.tar.gz
cd gcc-10.2.0
mkdir build
cd build
sudo ../configure --with-gmp=/usr/local/gmp-6.1.0 --with-mpfr=/usr/local/mpfr-3.1.4 --with-mpc=/usr/local/mpc-1.0.3 --with-isl=/usr/local/isl-0.18 --enable-languages=c,c++ --enable-threads=posix --disable-multilib --prefix=/usr/local/gcc-10.2.0
sudo make -j
sudo make check
sudo make install
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/gcc-10.2.0/lib64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/gcc-10.2.0/lib
sudo vi ~/.source.rc
export PATH=/usr/local/gcc-10.2.0/bin:$PATH
source ~/.source.rc
更换源可以参考:
https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
sudo apt-get update
sudo apt-get install software-name
参考:
https://blog.csdn.net/qq_23438131/article/details/52385843
https://www.cnblogs.com/oddcat/articles/9679221.html