Compilation pipeline
Phase | Command | Input | Output | |
---|---|---|---|---|
Preprocessing | gcc -E | source code .c | compilation unit .i | |
Compilation | gcc -S | compilation unit .i | assembly code .s | |
Assemble | gcc -c | assembly code .s | relocatable object file .o | |
Linking | gcc | relocatable object file .o | executable |
// hello_world.c
#include <stdio.h>
int main(int argc, char const *argv[]){
printf("Hello world");
return 0;
}
gcc -E hello_world.c -o hello_world.i
gcc -S hello_world.i -o hello_world.s
gcc -c hello_world.s // generates hello_world.o
gcc hello_world.o // generates a.out
To execute each of the phases in the pipeline, gcc
invokes different programs:
- the preprocessor
cpp
- the assembler
as
- the linker
ld