在 Debian 上使用 GCC 的完整指南
一 安装与验证
sudo apt update && sudo apt install build-essentialgcc --version、g++ --versionsudo apt install gcc。二 基本编译与运行
gcc hello.c -o hello./hellogcc -o app main.c util.cg++ main.cpp -o maingcc -Wall -Wextra hello.c -o hellogcc -g hello.c -o hellogcc -O2 hello.c -o hello三 常用编译选项与流程
gcc -E main.c -o main.igcc -S main.i -o main.sgcc -c main.c -o main.ogcc main.o -o maingcc -I/path/to/include hello.c -o hellogcc -DDEBUG hello.c -o hellogcc hello.c -lm -o hello(链接数学库 libm)gcc hello.c -static -lm -o hellogcc -pthread hello.c -o hello四 多版本管理与升级
sudo apt install gcc-9 g++-9sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 90sudo update-alternatives --config gcc(同法配置 g++)sudo apt update && sudo apt upgrade gcc五 进阶场景
sudo apt install gcc-arm-linux-gnueabiarm-linux-gnueabi-gcc hello.c -o hello_arm/etc/apt/sources.list 添加如 deb http://deb.debian.org/debian buster-backports main,然后 sudo apt install gcc-<version>-backportsbuild-essential libgmp-dev libmpfr-dev libmpc-dev),配置与编译(./configure --prefix=/usr/local/gcc-<version> && make -j$(nproc) && sudo make install),并更新 PATH-g,使用 gdb ./hello