Files
Linux/Docs/源码升级Gcc.md
offends cee91802b3
Some checks failed
continuous-integration/drone Build is failing
synchronization
2025-08-25 15:57:40 +08:00

89 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

> 本文作者:丁辉
# 源码升级Gcc
[Gcc源码文件下载](https://ftp.gnu.org/gnu/gcc/)
1. 下载源码包
```bash
wget https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz
```
2. 解压源码包
```bash
tar -zxvf gcc-*.tar.gz && cd gcc-*
```
3. 配置编译项
```bash
./configure --prefix=/usr/local/gcc-13.2.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib
```
> 遇到报错configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
>
> 解决方案gcc 目录下执行如下命令即可解决
>
> ```bash
> ./contrib/download_prerequisites
> ```
**构建参数**
| 参数 | 含义 |
| :-----------------------: | :---------------------------------------------------------: |
| ./configure | 源代码安装软件时用于配置软件包 |
| --enable-checking=release | 启用编译器的检查功能,但仅限于 release 模式 |
| --enable-languages=c,c++ | 指定 GCC 将支持 C 和 C++ 编程语言 |
| --disable-multilib | 禁用 GCC 的多架构支持,使其只会生成与主系统架构相匹配的代码 |
4. 开始编译
```bash
make
```
> 同时运行
>
> ```bash
> make -j 4
> ```
5. 编译安装
```bash
make install
```
6. 替换旧版本, 移除旧版本
```bash
mv /usr/bin/gcc /usr/bin/gcc.bak
mv /usr/bin/g++ /usr/bin/g++.bak
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
```
7. 制作软连接
```bash
ln -s /usr/local/gcc-13.2.0/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-13.2.0/bin/g++ /usr/bin/g++
ln -s /usr/local/gcc-13.2.0/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6
```
8. 查看动态库
```bash
strings /usr/lib64/libstdc++.so.6 | grep CXXABI
```
9. 验证版本
```bash
gcc --version
```