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;-Werrormakes 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 -lmCommon 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
-Iadds header paths;-L/-ladd 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
clang Command: Compile C/C++ in CIclang is the LLVM C/C++ compiler. Reference for -c, -o, -I, -std, -fsanitize, -Weverything, and the diagnosti…
make Command: Run Builds in CImake runs builds from a Makefile. Reference for -j, -C, -f, -B, -k, VAR=value overrides, and the Makefile err…
ld Command: The Linker in CIld is the GNU linker. Reference for -o, -l, -L, -shared, -rpath, --gc-sections, and the undefined-reference a…