Introduction
GCC (GNU Compiler Collection) is the original open-source compiler suite started by Richard Stallman in 1987. It remains the default system compiler on most Linux distributions and supports C, C++, Fortran, Ada, Go, and D across dozens of target architectures.
What GCC Does
- Compiles C, C++, Fortran, Ada, Go, D, and Objective-C to native machine code
- Optimizes code through multiple passes including loop vectorization, inlining, and LTO
- Targets over 60 processor architectures from ARM to x86_64 to MIPS and PowerPC
- Provides the libstdc++ C++ standard library and libgfortran runtime
- Includes sanitizers, profiling instrumentation, and static analysis warnings
Architecture Overview
GCC uses a three-stage pipeline. Each language frontend parses source into the GENERIC tree representation, which is lowered to GIMPLE for high-level optimizations. GIMPLE is then converted to RTL (Register Transfer Language) for target-specific optimization and register allocation before final assembly output. Plugins can hook into any stage.
Self-Hosting & Configuration
- Install from distribution packages:
apt install gcc g++ordnf install gcc gcc-c++ - Build from source with
./configure --enable-languages=c,c++,fortran && make -j$(nproc) - Select optimization level with
-O0through-O3,-Osfor size, or-Ofastfor aggressive - Use
-march=nativeto optimize for the current CPU microarchitecture - Enable link-time optimization with
-fltofor whole-program analysis
Key Features
- Broadest architecture support of any open-source compiler (60+ targets)
- Mature C++ standards support up to C++23 and ongoing C++26 work
- Profile-guided optimization (PGO) for data-driven performance tuning
- Plugin API for custom analysis and transformation passes
- Fortran frontend (gfortran) widely used in scientific and HPC computing
Comparison with Similar Tools
- LLVM/Clang — modular design, faster compile times for C/C++; fewer legacy target backends
- MSVC — Microsoft compiler for Windows; proprietary, strongest Windows SDK integration
- Intel oneAPI (ICX) — LLVM-based with Intel-specific optimizations; commercial focus
- TCC — tiny C compiler for fast iteration; minimal optimization, C only
FAQ
Q: When should I use GCC vs Clang? A: GCC has broader platform support and is the default on most Linux distros. Clang offers better diagnostics and faster compile times. Both produce competitive runtime performance.
Q: Does GCC support cross-compilation?
A: Yes. Configure a cross-compiler with --target=aarch64-linux-gnu to build for a different architecture.
Q: What is the latest stable GCC version? A: GCC follows annual major releases (e.g., GCC 14 in 2024). Check gcc.gnu.org/releases.html for the current version.
Q: Can GCC compile Rust or Swift? A: There is an experimental Rust frontend (gccrs) in progress. Swift is not supported.