What happens when you type gcc main.c

Daniel felipe Escobar chavez
2 min readFeb 3, 2021

--

hello programmer friends. I have prepared this blog to talk about what happens when we use the gcc command in a .c file when uploading a c code as I already mentioned this is used to compile a .c file.

gcc is a command that is implemented in Linux and it has the function of compiling, assembling and linking a file that we need and also has options to stop these processes. as I have named these are the phases that happen when we decide to use this command so now we are going to get into the matter and see what each one is based on.

processing: as it says if you name this phase it is responsible for the processing of the code where the variables are organized, also before this there is a preprocessing. it is also the phase where comments are eliminated and files are included, to test only the processor I can use the command:

$ gcc -E file -c

compilation: In this part of the process, the compiler has the function where the code is translated into the assembly language so that it can be recognized by the assembly,to test only the processor I can use the command:

$ gcc -c file

Assembly: this process is similar to the previous one and with the help of this command you can execute the command on your own:

[root @ host ~] # as helloworld.s -o helloworld.o with this in mind the file is already mounted and ready to go to the last part of this process, in conclusion the assembler converts the assembly code into object code

to review the process in assembly you can try the command:

$ gcc -S file

Linker: finally, in binding with printf, it prints the instruction that is in the .c file and this concludes this process.

This whole process is important to take into account since with it you can execute the codes that you create and also have them with names to identify them, here I will leave an image where you can see this process in a better way.

It is important to keep this information in mind as this command is used a lot in the c language. well folks that’s it, until next time.

--

--