GCC(GNU Compiler Collection)是 GNU 项目的编译器套件,支持 C、C++、Fortran、Go 等多种语言。在 Linux 上是最常用的 C/C++ 编译器。
安装(Ubuntu/Debian)
通过 PPA 安装较新版本:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install gcc-14 g++-14 # 举例:安装 gcc 14设置默认版本
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 100常用编译选项
| 选项 | 用途 |
|---|---|
-Wall | 开启常见警告 |
-Wextra | 开启额外警告 |
-O2 | 优化级别 2(推荐 Release) |
-g | 生成调试信息(DWARF) |
-std=c++20 | 指定 C++ 标准 |
-fsanitize=address | 开启 AddressSanitizer |