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
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 + pthreadsOptions
| Flag | What it does |
|---|---|
| -c | Compile/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 -Werror | Enable warnings; -Werror makes them fatal |
| -O0/-O1/-O2/-O3 -g | Optimization 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.