gcc main.c

What happens when you type gcc main.c into your bash?

Compiling process

GNU compiler collection (gcc) is a collection of compilers for many different languages. It takes input of a file in a language and outputs (unless otherwise told) an executable of the code you had in your file.

In this case it takes the file main.c which is a c source file and turns it into an executable file.

Example of c language

It looks tidy and neat but it really performs 4 processes on your code. It gets sent through the preprocessor first which strips out all comments and then inserts all the code from your header files into your program. Lastly it exchanges all your macros with the actual code of the macro.

Next it gets passed through the compiler. What the compiler does is change the code from the high level language to assembly language which is basically just a harder to read version of the same code.

Sample of assembly language

After the compiler comes the assembler. The code gets transformed into machine code (binary). The computer can’t understand our language or the intermediary assembly language. It needs the code to be in 1’s and 0’s to execute it.

Example of binary

Finally it reaches the linker. What the linker does is take all your files if there was more than one and collate them together as well as any libraries you used in your program into one file that is executable.

Example of whole compilation process
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.