What happens when you type gcc 
                          main.c?

What happens when you type gcc main.c?

No hay texto alternativo para esta imagen

Have you ever wondered what happens when you create a C-based code and compile it with GCC?

very well if you asked yourself this question. This blog will help you better understand how it works.

The first step is to create a file that in this case will be called main.c, once the next step has been created is: COMPILE.

And what is compiling? the answer is simple, programming this word means that a program will translate from a high-level language, such as C, to the machine language, binary. Making the compiler, the translator program that in this case is GCC, responsible for our system to understand what our program does.

The compilation of a program, which in turn, consists of four main steps, which are: Processor, compiler, assembler and linker.

so to do all this process with our "main.c" program we must use GCC, which is called GNU Compiler Collection for its initials, and it works with languages like C, C ++, Objective-C, Fortran, Ada, and Go. in this example we will use C.

No hay texto alternativo para esta imagen

In this image we see that the file "main.c" is already created, and we see its content (an example code in C language), well followed by this, what we will do is use GCC, and show the result.

No hay texto alternativo para esta imagen

Here we see that an output file has been created, but what happened? That is what we are going to talk about next.

No hay texto alternativo para esta imagen

1. processor:

When writing the gcc command accompanied by the name of our file "gcc main.c", what gcc does first with the processor is to eliminate the comments that were in main.c, the second, add the code of the header and the source file, Third, remove the macros and put the corresponding code.

No hay texto alternativo para esta imagen

2. Compiler

This generates the assembly code from the code that the processor gave it.

No hay texto alternativo para esta imagen

3. Assembler

Since our computer still does not understand the language that is written in our program, the assembler converts it into binary code, which is the code that our machine can understand and execute. But everything does not end here, we still need a process.

No hay texto alternativo para esta imagen

4. Linker

The linker creates the links between the binary code of our program and the libraries, and in this way we obtain the executable file called a.out.

In order for our program to have the name that seems best to us, we use the gcc option "-o" which allows us to do this, like this:

No hay texto alternativo para esta imagen


要查看或添加评论,请登录

Didier Revelo的更多文章

  • ?Quién es el impostor?

    ?Quién es el impostor?

    ?Quién es el impostor?, huuum, aunque suena a título de videojuego o a película de espías, esta es la pregunta más…

    1 条评论
  • LO BUENO, LO MALO Y LO FEO DE QUERER SER PROGRAMADOR

    LO BUENO, LO MALO Y LO FEO DE QUERER SER PROGRAMADOR

    Primero dire que todo lo contenido en esta publicación es mi punto de vista y no debería afectar la decisión de…

    4 条评论
  • ONE STEP FORWARD, ONE STEP TO THE FUTURE.

    ONE STEP FORWARD, ONE STEP TO THE FUTURE.

    Our project sought the connection and consumption of the API Stripe, with the banking platform called Bankity. our team…

    4 条评论
  • WHY USE LIBRARIES? RELOADED.

    WHY USE LIBRARIES? RELOADED.

    Libraries. As we create programs, we find that some pieces of code are repeated over and over again in our work and we…

  • WHY USE LIBRARIES?

    WHY USE LIBRARIES?

    If we think for a moment about a library, we could conclude that libraries store information, but this would only be…

  • What is the difference between a hard link and a symbolic link?

    What is the difference between a hard link and a symbolic link?

    If you are starting in the fascinating world of programming, and you have come across the words "HARD LINK" and…

  • What happens when you type ls *.c

    What happens when you type ls *.c

    When we think of a command we must also think of the environment that performs its function, and for this case, this…

社区洞察

其他会员也浏览了