Building a C program is a pipeline: preprocess → compile → assemble → link. Understanding stages helps debug weird errors.
Stages
- Preprocessor — expands
#includeand macros - Compiler — translates C to assembly
- Assembler — produces machine code object files
- Linker — combines objects and libc into an executable
Useful gcc flags
-std=c11— language standard-Wall -Wextra— warnings-g— debug symbols for gdb-O2— optimizations for release builds
Important interview questions and answers
- Q: Undefined reference error?
A: Linker cannot find a function definition—missing source file or library. - Q: Multiple definition error?
A: Same global symbol defined in more than one translation unit.
Self-check
- Which stage handles #include?
- What flag adds debug symbols?
Tip: Run gcc -E to see preprocessed output when macro or include issues confuse you.
Interview prep
- Undefined reference?
Linker error—function declared but not defined, or required library not linked.
- Preprocessor stage?
Handles
#include,#define, and conditional compilation before the compiler sees C code.