make it rollin!
The compilation process in C language.
What is “gcc”?
First I will explain what gcc is and why we use it.
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.
Working with C, C + +, Objective C and Fortran, the gcc is able to receive a source code in any of these languages and generate an executable binary program in the language of the machine where you run.
How is the compilation process?
During compilation of a C program the compilation is started off with preprocessing the directives (e.g., #include and #define). The preprocessor (cpp — c preprocessor) is a separate program in reality, but it is invoked automatically by the compiler. For example, the
#include <stdio.h> command in line 1 of
filaname.c tells the preprocessor to read the contents of the system header file
stdio.h and insert it directly into the program text. The result is another file typically with the
.i suffix. In practice, the preprocessed file is not saved to disk unless the
-save-temps option is used.
In this phase compilation proper takes place. The compiler compiles the pre-processed source code into assembly code for a specific processor.
In this phase the filename.s is taken as input and turned into filename.o by assembler. This file contain machine level instructions. At this phase, only existing code is converted into machine language, the function calls like printf() are not resolved.
This is the final stage in compilation of “Hello World!” program. This phase links object files to produce final executable file. An executable file requires many external resources (system functions, C run-time libraries etc.). This file is now ready to be loaded into memory and executed by the system.
To compile a file we type “gcc” in terminal followed by the name of the file where the source code is.
We would do it this way:
vagrant@vagrant-ubuntu-trusty-64: gcc filaname.c