GCC C/C++ compiler
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
gcc hello.c -o hello
gcc -Wall -Wextra -g -O0 x.c
gcc -c x.cgcc a.o b.o -o app
gcc -O2 x.cg++ x.cpp -o x
gcc -fsanitize=address -g x.c
gcc --versionConcepts
- x.c source
- x.i preprocessed
- x.s assembly
- x.o object
- a.out executable
Compile and link
gcc <file.c> -o <out>
gcc -c <file.c>
gcc -E <file.c>
gcc -S <file.c>
gcc <a.o> <b.o> -o <out>
gcc <a.c> <b.c> -o <out>
gcc -v <file.c>
Language standard
gcc -std=c17 <file.c>
gcc -std=gnu11 <file.c>
g++ -std=c++20 <file.cpp>
gcc -pedantic <file.c>
Warnings
gcc -Wall <file.c>
gcc -Wextra <file.c>
gcc -Werror <file.c>
gcc -Werror=<name> <file.c>
gcc -Wno-<name> <file.c>
gcc -Wshadow -Wconversion <file.c>
gcc -fanalyzer <file.c>
Optimization
gcc -O0 <file.c>
gcc -O2 <file.c>
gcc -O3 <file.c>
gcc -Os <file.c>
gcc -Og <file.c>
gcc -Ofast <file.c>
gcc -march=native <file.c>
gcc -flto <file.c>
Debug and profile
gcc -g <file.c>
gcc --coverage <file.c>
Sanitizers
gcc -fsanitize=address -g <file.c>
gcc -fsanitize=undefined -g <file.c>
gcc -fsanitize=address,undefined -g <file.c>
gcc -fsanitize=thread -g <file.c>
Include and link paths
gcc -I<dir> <file.c>
gcc -L<dir> <file.c> -l<name>
gcc <file.c> -l<name>
gcc <file.c> -lm
gcc -pthread <file.c>
gcc -static <file.c>
gcc -Wl,<opt> <file.c>
gcc -Wl,-rpath,<dir> <file.c>
gcc $(pkg-config --cflags --libs <pkg>)
<file.c>
Macros
gcc -D<name> <file.c>
gcc -D<name>=<value> <file.c>
gcc -dM -E -x c /dev/null
Dependencies and libraries
gcc -MMD -MP -c <file.c>
gcc -M <file.c>
gcc -MM <file.c>
gcc -fPIC -c <file.c>
gcc -shared -o lib<name>.so <a.o>
ar rcs lib<name>.a <a.o> <b.o>
LD_LIBRARY_PATH=<dir> ./<app>
Inspect the compiler
gcc --versiongcc -dumpmachine
gcc -fverbose-asm -S <file.c>
Recipes
gcc -std=c17 -Wall -Wextra -Werror \ -g -O0 -fsanitize=address,undefined \ src/*.c -o app
# compilegcc -O2 -MMD -MP -c src/main.c -o build/main.o# linkgcc build/main.o -o app -lm# make: -include build/*.d
gcc -fPIC -shared -o libfoo.so foo.cgcc main.c -L. -lfoo -Wl,-rpath,'$ORIGIN' -o app./app
gcc -O2 -S -fverbose-asm x.c -o x.sgcc -g -c x.c && objdump -dS x.o | less



