Compilation process of a program.

Before knowing the compilation processes of a program, we must know what is a “Compiler”

What is a compiler?
A compiler is a computer program that translates a program written in one programming language into another programming language, generating an equivalent program that the machine will be able to interpret. Usually the second language is machine language (binary), but it can also be an intermediate code (assembly example), this translation process is known as compilation. There are many compilers among which are:
Borland Turbo C, GCC, Tiny C Compiler, etc.
This time we will work with GCC, which in fact its acronyms are GNU Compiler Collection and it is one of the best known and most used compiler.

Do all programming languages ​​have to be compiled?
No, there are programming languages ​​that should not be compiled (they are interpretation languages); like python, ruby, among others, we will talk about these in a future post.
In this occasion we will talk about the c programming language, all the examples shown below will be in this language.

Compilation process.
The world of compilers is a very extensive world, but the fundamental processes of compiling a program are:
Pre-processor, compiler, assembler, linking.

Let’s take a closer look at these processes.
Preprocessing: The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control.

If you want to print the result of the preprocessing stage, type this:

Compilation: At this stage, the preprocessed code becomes some assembly instructions ideal to be read and understood by humans. This part of the process will make a file containing such assembly instructions with the extension (.o).

To get only the assembly code, type the following:

Assembly: Once the compilation process finishes, the compiler will proceed to convert that assembly code to machine code (binary).

To make a result file, type the next code:

When this code is executed, it will make a file with the extension (.s).

Linking: Linking is the final step of compilation. The linker merges all the object code from multiple modules into a single one. If we are using a function from libraries, linker will link our code with that library function code. In static linking, the linker makes a copy of all used library functions to the executable file. In dynamic linking, the code is not copied, it is done by just placing the name of the library in the binary file.

The outcome of this linking process is a executable program a.out. To compile a program, use the following command:

In total these are the four fundamental processes that a code goes through (when it is written in a language that must be compiled).

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Is there an age limit to start coding?

Coder Workspace

C storage classes

I Feel Like A Total Hacker

Deploying WordPress Application on Kubernetes and AWS using Terraform

Common coding mistakes that new developers make in a professional environment

Learn Git for free with this amazing tool !

Mystery Of Satisfaction!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrés Felipe Sepúlveda Jimenez

Andrés Felipe Sepúlveda Jimenez

More from Medium

Leetcode Series. No 198: House Robber

Today lets talk about the linked list as a logic not implementation

Engineering Journal: SDC

Leetcode 581. Shortest Unsorted Continuous Subarray