when we start a topic we have to try to know all its terms
let’s start with the root to understand that is compiled in gcc let’s start with c.
what is c?
C is a general-purpose programming language that offers a syntactic economy, simple flow control and structures, and a good set of operators. It is not a very high level of language and rather a small, simple language and is not specialized in any type of application. This makes it a powerful language, with an unlimited field of application and above all, it is quickly learned. In a short time, a programmer can use the entire language.
Now we know that it’s c how we can create a c file in our terminal?
commonly the extension of our c files are going to be .c
Little by little, we are approaching the main question but we still have some unknowns like which editors can run a .c file and the truth is that we can run it in most text editors like emacs, vi, or atom.
ready now when we create a .c file it is called a program, to be able to see its result we have to use a compiler here enters gcc.
what is gcc?
GCC is an integrated compiler of the GNU Project for C, C++, Objective C, and Fortran; it is capable of receiving a source program in any of these languages and generating an executable binary program in the language of the machine where it is to be run.
The syntax is this:
these are some of the options that can be used with gcc.
-E: Preprocess only; do not compile, assemble or link
-S: Compile only; do not assemble or link.
-c: Compile and assemble, but do not link.
-o: Place the output into <file>.
The compilation process involves four successive stages. To go from a source program written by a human to an executable file, it is necessary to perform these four stages in succession. The Gcc and G++ commands are capable of performing the entire process at once.
At this stage, the directives to the Preprocessor are interpreted. Among other things, Variables initialized with #define are replaced in the code by their value wherever their name appears.
The Compilation transforms the C Code into the Processor’s own Assembly Language of our machine.
Assembly transforms a program written in Assembly Language into Object Code, a binary file in Machine Language executable by the Processor.
The C/C++ functions included in our code, such as printf() in the example, are already compiled and assembled in existing libraries in 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 assembled in object code with the existing code in the libraries.
When we type gcc “name of file” it creates an executable file called a.out if the compiler doesn’t catch any errors it creates.
when we type gcc “name of file” it creates an executable file called a.out if the compiler doesn’t catch any errors it creates
in this example, we are going to see how gcc is executed and creates the a.out
here we can appreciate how the a.out executable is created now we execute it,we simply put this ./a.out and it will run.
At this point, you could conclude that by writing gcc name-of-file, an executable file is created and compiled, remember that every time you make an update to your file you must write the gcc again so that the a.out is updated.
Linux is the base of everything, don’t ever stop learning.