What happens when you type gcc main.c

Reese Hicks
1 min readJun 11, 2020

Within the Linux operating system, there is a built-in command called “gcc”. It is a C compiler, which basically means it takes source code (C language script) and turns it into an executable file. Here’s how:

There are three steps gcc takes to fulfill this command. First, it reads the source file, or C language script. Second, it processes it. Thirdly, gcc links it with a runtime library.

The pre-processor takes care of the first step. It will remove comments written by the author, then add a header, and replace macros with the actual thing.

The assembler assembles the above code into whats called “object code” which can be read by the linker.

The linker will take the code and put it all into a single file and make it executable. Two common outputs are readable for windows (.exe) and UNIX / UNIX-like systems like Linux. The Linux files normally do not need an extension.

--

--