The compilation process make’s a series of tasks that translate from human readable code to a code that the machine understand (Binary notation).
To make this process possible, we must to type in the terminal or console the gcc command and the C file to compiled:
- gcc file.c
Once gcc has been invoked, will starting to make the following process:
Via the GNU C preprocessor (cpp.exe), which includes the headers (#include) and expands the macros (#define).
cpp file.c > file.i
the resultant intermediate file “file.i” contains the expanded source code.
This step compiles the pre-processed source code into assembly code for a specific processor.
gcc -S file.i
The -S option specifies to produce assembly code, instead of object code. The resultant assembly file is “file.s”
The assembler (as.exe) converts the assembly code into machine code in the object file “file.o”.
as -o file.o file.s
Finally, the linker (ld.exe) links the object code with the library code to produce an executable file “file.exe”.
ld -o file.exe hello.o
In the following image we can see the behavior of gcc in a graphic instance.