Skip to content
Latchkey

gcc Command: Compile C in CI

gcc preprocesses, compiles, assembles, and links C (and other) source.

gcc is the default C toolchain on most Linux runners. In CI the recurring failures are missing header paths and missing libraries, both of which usually trace back to an uninstalled -dev package on the runner image.

Common flags

  • -c - compile/assemble only, do not link (produces .o)
  • -o NAME - name the output file
  • -I DIR - add a header search directory
  • -L DIR / -lNAME - add a library dir / link libNAME
  • -Wall -Wextra - enable warnings; -Werror makes them fatal
  • -O2 / -O0 -g - optimize / debug build with symbols
  • -std=c11 - select the C language standard

Example in CI

Compile and link a small C program with warnings and optimization:

shell
gcc -std=c11 -Wall -Wextra -O2 -Iinclude src/main.c -o app -lm

Common errors in CI

  • fatal error: foo.h: No such file or directory - install the -dev package or add -I
  • undefined reference to func - missing library; add -lNAME after the sources
  • cannot find -lfoo - the .so/.a is not in any -L directory
  • error: unknown type name - missing include or wrong -std

Key takeaways

  • -I adds header paths; -L/-l add and link libraries (order matters).
  • "No such file or directory" on a header means a missing -dev package.
  • "undefined reference" is a link-time missing-library error, not a compile error.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →