Skip to content
Latchkey

gcc: Usage, Options & Common CI Errors

gcc compiles and links C (and other) source into objects and executables.

gcc is the default C toolchain on most Linux runners. In CI the recurring failures are missing header paths (-I) and missing libraries (-l/-L), both of which trace back to an uninstalled -dev package.

What it does

gcc is the GNU Compiler Collection driver. It preprocesses, compiles, assembles, and links source files into object files or executables, invoking cc1, as, and ld as needed. Despite the name it also drives Fortran, Go, and (via g++) C++.

Common usage

Terminal
gcc -c file.c -o file.o                 # compile only, no link
gcc -Wall -Wextra -O2 main.c -o app     # warnings + optimize
gcc main.c -I./include -L./lib -lfoo    # add header & lib paths
gcc -g -O0 main.c -o app                # debug build, no optimize
gcc *.c -o app -lm -lpthread            # link math + pthreads

Options

FlagWhat it does
-cCompile/assemble only; do not link
-o <file>Name the output file
-I <dir>Add a header search directory
-L <dir> / -l<name>Add a library dir / link libname
-Wall -Wextra -WerrorEnable warnings; -Werror makes them fatal
-O0/-O1/-O2/-O3 -gOptimization level / debug info

Common errors in CI

fatal error: foo.h: No such file or directory - the header is not on the include path; install the -dev/-devel package (e.g. libssl-dev) or add -I<dir>. "undefined reference to func" at link time means a library is missing - add -l<name> AFTER the source files (link order matters). "cannot find -lfoo" means the .so/.a is not in any -L dir. With -Werror a new warning fails the build; pin warning flags deliberately in CI.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →