C compilation process
What is GCC?
The GNU Compiler Collection, commonly known as GCC, is a set of compilers and development tools available for Linux, Windows, various BSDs, and a wide assortment of other operating systems. It includes support primarily for C and C++ and includes Objective-C, Ada, Go, Fortran, and D. The Free Software Foundation (FSF) wrote GCC and released it as completely free (as in libre) software.
Command to compile
gcc <file.c>
Process
Preprocessing:
he C compilation begins with pre-processing of source file, in this step the comments are removed, include headers and expand macros
gcc -E main.c > main
Compilation:
In this stage, the preprocessed code is translated to assembly code that is specific to the operating system.
gcc -S main.c > main.s
Assemble:
In this stage, an assembler translates the assembly instructions to object code to be run by the OS.
gcc -c main.c > main.o
Linking:
In this stage, the processor has to link pieces of the program that are missing or out of order. By “linking” all these functions together, the result is a final executable program.
gcc main.c -o myexecutablefile