Linux GCC编译器安装步骤
一 快速安装 使用包管理器
二 从源码编译安装 适用于需要特定版本或离线环境
mkdir -p ../gcc-build && cd ../gcc-build
../gcc-13.2.0/configure --prefix=/usr/local/gcc-13.2.0 \
--enable-languages=c,c++ --enable-lto --disable-multilib
echo 'export PATH=/usr/local/gcc-13.2.0/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
三 安装后验证与常用配置
echo 'int main(){return 0;}' > hello.c
gcc -O2 -Wall -g hello.c -o hello && ./hello && echo $?
export CC=/usr/bin/gcc
export CXX=/usr/bin/g++
四 常见问题与处理