gcc(1)

GNU C and C++ compiler

Section 1 gcc bookworm source
💡 On Debian/Ubuntu, g++ is provided by gcc(1) — g++ is the C++ frontend of GCC — it accepts the same options

Description

GCC

NAME

gcc, g++ — GNU C and C++ compilers

NOTE

The GCC compiler suite does not ship a traditional man page in Debian. For complete documentation, use:

  • info gcc — full reference manual
  • gcc --help — quick option summary
  • gcc --version — compiler version info
  • Online: gcc.gnu.org/onlinedocs

SYNOPSIS

gcc [options] file...

COMMON OPTIONS

Compile and link: gcc -o output source.c
Compile only: gcc -c source.c
Optimize: gcc -O2 -o output source.c
Debug info: gcc -g -o output source.c
Warnings: gcc -Wall -Wextra source.c
Set C standard: gcc -std=c11 source.c

Options

-o file
Write output to file instead of a.out
-c
Compile and assemble, but do not link
-g
Produce debugging information
-O[level]
Optimize: -O0 (none), -O1, -O2, -O3, -Os (size)
-Wall
Enable all common warnings
-Wextra
Enable additional warnings
-std=standard
Specify C/C++ standard (c11, c17, c++17, c++20...)
-I dir
Add dir to the include file search path
-L dir
Add dir to the library search path
-l lib
Link with library liblib.a or liblib.so
-D macro
Define macro for the preprocessor
-E
Preprocess only; do not compile
-S
Compile to assembly; do not assemble
-shared
Produce a shared object (dynamic library)
-static
Link against static libraries only
-v
Verbose output; show commands executed

See Also