LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

What are the stages a C program goes through from source code to executable?

Compile each .c to assembly, assemble that to a .o object file, then link all the objects plus the C runtime into one executable.

Compilation pipeline: main.c and swap.c each compiled to assembly, assembled to object files, then linked with the CRT into one executable

* Each source file travels its own compile → assemble path to a .o; the linker fuses all objects plus the C runtime into the final executable. *

The compilation pipeline:

Stage Tool Input Output
1. Compilation cc1/cpp .c file .s (assembly)
2. Assembly as .s file .o (relocatable object)
3. Linking ld/collect2 .o files + libraries executable

Key insight: Each .c file is compiled independently to its own .o file. The linker combines all .o files plus the C runtime library (CRT) into the final executable.

# View the full compilation process
$ gcc -v -O2 -Wall -g -o prog main.c swap.c

Tip: GCC is actually a "compiler driver" - it orchestrates calls to the preprocessor, compiler, assembler, and linker.

Go deeper:

From Quiz: REVE1 / Program Execution | Updated: Jul 14, 2026