GCC (GNU Compiler Collection) is a compiler (with front, optimiser, and back-end) primarily for C. Its sister project, G++, compiles primarily for C++. Both compilers target an extremely wide range of architectures, including popular (x86, ARM, RISC-V), less popular (PowerPC, Alpha, MIPS), and esoteric or embedded processors.

Flags

Both compilers share common flags to modify compilation behaviour.

  • No flags — compiles to an executable called a.out (on Linux) or a.exe (on Windows).
    • -o <NAME> — specifies the output executable file name.
  • Compiler phases
    • -E — stops the compiler at the preprocessor stage.
    • -S — stops the compiler after assembly generation but before the assembler.
    • -C — compiles without using the linker.
    • -save-temps — outputs all intermediate files (preprocessor, assembly, executable).
  • Debug behaviour
    • -Wall — enables compiler warnings.
    • -g — compiles in debug mode.
  • Language-specific
    • -std=<VERSION> — compiles with a specific language version.
      • For example, to compile with C++17, we can do -std=c++17.