Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Four Stages, Four Tools

โญโญโญ advancedโณ 16 min read๐Ÿ“ Lesson 181 of 225

What cpp, cc1, as, and ld each produce โ€” and the gcc flags that stop at each boundary.

gcc is a driver, not one program

One gcc hello.c command orchestrates four stages:

  1. Preprocessor (cpp): expands macros and includes โ†’ still C text.
  2. Compiler proper (cc1): C text โ†’ assembly text.
  3. Assembler (as): assembly โ†’ object file (machine code + symbol table).
  4. Linker (ld): objects + libraries โ†’ executable.

gcc -E stops after preprocessing, -S after compiling, -c after assembling. Each flag hands you an intermediate artifact you can actually read.

Why the boundaries matter

  • -E output shows what macros really did โ€” the ground truth of module 9.
  • -S output is where you watch optimization happen (module 4's claims become visible).
  • -c produces the .o whose symbol table the linker resolves โ€” and whose collisions and missing definitions produce link errors.

The linking step defines C's programming model

Undefined reference, multiple definition, and static-vs-external linkage are all linker concepts. Declaring a function without defining it compiles fine (the compiler trusts you) and fails only at link โ€” which is why header/implementation drift surfaces so late.

โšก Now practice

Ready to Code
Pipeline DrillsStop at each stage, inspect the artifacts, and predict linker behavior โ€” the toolchain as a laboratory. These challenges use system() to drive real gcc/ar/nm.
4 challenges ยท ยท ~24 min