0Pricing
C Academy · Lesson

Compiling Multiple Files

Build a multi-file program.

From Source to Program

Turning multi-file C source into an executable happens in two stages: compiling and linking.

Each .c file is compiled separately into an object file. Then the linker combines all object files, resolving references between them, into one runnable program.

The One-Command Build

The simplest approach hands every source file to gcc at once. The compiler builds each, then links them automatically.

The -o flag names the output program. List all .c files; headers are pulled in via #include and are not listed here.

gcc main.c math_utils.c -o app

All lessons in this course

  1. Header and Source Files
  2. Include Guards
  3. extern and Linkage
  4. Compiling Multiple Files
← Back to C Academy