从源码编译安装 GCC 10.1.0
目录
⚠️ 警告:耗时长(1~2小时),需要至少 10GB 磁盘空间,仅建议用于测试或特殊需求。
1. 安装编译依赖
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y glibc-devel glibc-static libstdc++-static zlib-devel bzip2
2. 下载 GCC 10.1.0 源码
cd /tmp
wget https://mirrors.aliyun.com/gnu/gcc/gcc-10.1.0/gcc-10.1.0.tar.gz
tar -xf gcc-10.1.0.tar.gz
cd gcc-10.1.0
3. 下载依赖库(非常重要)
GCC 编译需要 GMP、MPFR、MPC 等库:
./contrib/download_prerequisites
这会自动下载
gmp、mpfr、mpc等依赖。
4. 创建构建目录
cd ..
mkdir gcc-build
cd gcc-build
5. 配置编译选项
../gcc-10.1.0/configure \
--enable-languages=c,c++ \
--disable-multilib \
--enable-shared \
--enable-threads=posix \
--with-system-zlib \
--prefix=/opt/gcc-10.1.0
--prefix=/opt/gcc-10.1.0:安装到/opt/gcc-10.1.0--enable-languages=c,c++:只编译 C/C++ 编译器,节省时间
6. 编译(根据 CPU 核心数调整 -j)
make -j$(nproc) all
⏳ 时间很长,请耐心等待(1小时以上)
7. 安装
sudo make install
8. 添加到系统路径
echo 'export PATH=/opt/gcc-10.1.0/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/opt/gcc-10.1.0/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
9. 验证安装
gcc --version
g++ --version
输出应为:
gcc (GCC) 10.1.0
Do not communicate by sharing memory; instead, share memory by communicating.

浙公网安备 33010602011771号