What happens when you type gcc main.c
The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain and the standard compiler for most projects related to GNU and Linux, including the Linux kernel. The Free Software Foundation (FSF) distributes GCC under the GNU General Public License (GNU GPL). GCC has played an important role in the growth of free software, as both a tool and an example.
The process
The process is a union of 4 steps:
Preprocessor (.c)
Compilation (.i)
Assembler (.s)
Linker (.o) Are 4 but, in the 4, we just create the binary, not execute it.
1. Preprocessor
In this part, is the first program invoked by compiler and process directives like #include, #define and #if. That directives are not specifics of C. We can use it in any type of files If we want to create just this part, we need to execute the following.
gcc -E main.c
2. Compilation
The words compilations means translate a programming language to a machine language, and we can do that with
gcc -S main.c
3. Assembler
The assembly transforms the program written in assembly language into object code, a binary file in machine language executable by the processor
4. Linked
The C / C ++ functions included in our code, such as printf () in the example, are already compiled and assembled in existing libraries on the system. It is necessary to incorporate somehow the binary code of these functions to our executable. This is the linking stage, where one or more modules are put together in object code with the existing code in the libraries.