Compiling a C program with GCC (gcc main.c -o main) appears instantaneous, but the compiler executes four distinct transformation stages under the hood: Preprocessing, Compilation to Assembly, Assembly to Machine Code, and Linking.

Step-by-Step GCC Stage Commands

GCC Pipeline Commandsbash
# Stage 1: Preprocessor (Expands #include, #define macros)
gcc -E main.c -o main.i
 
# Stage 2: Compilation (Translates C code to Assembly code)
gcc -S main.i -o main.s
 
# Stage 3: Assembler (Assembles Assembly code to binary Machine Code Object file)
gcc -c main.s -o main.o
 
# Stage 4: Linker (Links object files & libc libraries into ELF Executable)
gcc main.o -o main