build gcc

发布于:2025-03-06 ⋅ 阅读:(21) ⋅ 点赞:(0)

 1,下载源码

wget https://gcc.gnu.org/pub/gcc/infrastructure/mpfr-4.1.0.tar.bz2
 wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
 wget https://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.2.1.tar.gz


 git clone --mirror https://github.com/gcc-mirror/gcc.git
 cd ./ex/
 git clone ../gcc.git
 cd gcc
 git checkout releases/gcc-12.2.0

2,编译

cd gmp-6.1.0 && \
./configure --prefix=/home/hanmeimei/ex_gcc/tmp1/local/gmp-6.1.0 && \
make -j && sudo make install && \
cd ..

cd mpfr-4.1.0 && \
./configure --prefix=/home/hanmeimei/ex_gcc/tmp1/local/mpfr-4.1.0 --with-gmp=/home/hanmeimei/ex_gcc/tmp1/local/gmp-6.1.0 && \
make -j && sudo  make install && \
cd ..

cd mpc-1.2.1 && \
./configure --prefix=/home/hanmeimei/ex_gcc/tmp1/local/mpc-1.2.1 --with-gmp=/home/hanmeimei/ex_gcc/tmp1/local/gmp-6.1.0 --with-mpfr=/home/hanmeimei/ex_gcc/tmp1/local/mpfr-4.1.0  && \
make -j && sudo make install && \
cd ..


cd gcc && \
./configure --prefix=/home/hanmeimei/ex_gcc/tmp1/local/gcc-12.2.0 --enable-checking=release  --disable-multilib --with-gmp=/home/hanmeimei/ex_gcc/tmp1/local/gmp-6.1.0 --with-mpfr=/home/hanmeimei/ex_gcc/tmp1/local/mpfr-4.1.0 --with-mpc=/home/hanmeimei/ex_gcc/tmp1/local/mpc-1.2.1 && \
make -j &&sudo make install    

3,检查

4, 在高版本系统中编译低版本 GCC

通常会出现如下类似的错误:

gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /lib/x86_64-linux-gnu/libicuuc.so.70)

这是使用 bootstrap 方式编译

step1. 准备环境


 

sudo apt-get update
sudo apt-get install build-essential bison flex texinfo

step2. 下载并解压 GCC 源码

wget https://ftp.gnu.org/gnu/gcc/gcc-7.4.0/gcc-7.4.0.tar.gz
tar xf gcc-7.4.0.tar.gz
cd gcc-7.4.0

step3. 下载依赖

./contrib/download_prerequisites

step4. 配置和编译

mkdir build && cd build
../configure \
    --prefix=/opt/gcc-7.4.0 \
    --enable-languages=c,c++ \
    --disable-multilib \
    --with-boot-ldflags='-static-libstdc++ -static-libgcc' \
    --with-stage1-ldflags='-static-libstdc++ -static-libgcc'

make BOOT_CFLAGS='-O2' bootstrap -j$(nproc)
sudo make install


网站公告

今日签到

点亮在社区的每一天
去签到