What is and what happens when you type gcc main.c?

GCC (GNU Compiler Collection)

The original GNU C Compiler (GCC) is developed by Richard Stallman, the founder of the GNU Project. Richard Stallman founded the GNU project in 1984 to create a complete Unix-like operating system as free software, to promote freedom and cooperation among computer users and programmers. GCC is an integrated distribution of compilers for several major programming languages. These languages currently include C, C++, Objective-C, Objective-C++, Java, Fortran, and Ada.

To execute code and create an object file, the computer must communicate in machine language, which is binary code (base-2); in this case, the Unix command must be used to compile: GCC main.c

What happens when type gcc main.c into the terminal?

Steps when building a code compilation process:

1.Read the source file
2. Process the file
3. Links the file to a runtime library.

The Four Stages of Compiling a C Program

  • Prepocessing
  • Compiler
  • Assembler
  • Linkin

The preprocessor handles statements or lines of code that begin with the “#” character, which are called “preprocessor directives. The preprocessor reads and processes each source code file one at a time from top to bottom. It does not change the contents ofany of the files that it processes but creates a temporary file that contains the processed source code.

The preprocessor handles directives that begin with the # character and creates a temporary file to store its output. The compiler reads the temporary file and continues the compilation process.


A Compiler is a program that converts a number of statement of program into binary language, but it is more intelligent than interpreter because it goes through the entire code at once and can tell the possible errors and limits and ranges.But this makes it’s operating time a little slower.it is platform-dependent.its help to detect error and get displayed after reading the entire code by compiler.

In other words we can say that, “Compilers turns the high level language to binary language or machine code at only time once”, it is known as Compiler.

The compiler actually consists of three separate programs:

  1. The preprocessor
  2. The code translator, which is also often called the compiler
  3. The linker (also called a loader on some operating systems)


The assembler is a program which converts assembly language into machine code. In assembler, a programmer can write a program into sequence of assembler instructions, the sequence of assembler instruction is known as source code and source program.


For a code to run we need to include a header file or a file saved from the library which are pre-defined if they are not included in the beginning of the program then after execution the compiler will generate errors, and the code will not work.

Linker is a program that holds one or more object files which is created by compiler, combines them into one executable file. Linking is implemented at both time,load time and compile time. Compile time is when high level language is turns to machine code and load time is when the code is loaded into the memory by loader.

Linker is of two types:

Dynamic Linker:

  • It is implemented during run time.
  • It requires less memory.
  • In dynamic linking there are many chances of error and failure chances.
  • Linking stored the program in virtual memory to save RAM,So we have need to shared library

Static Linker:

  • It is implemented during compilation of source program.
  • It requires more memory.
  • Linking is implemented before execution in static linking.
  • It is faster and portable.
  • In static linking there are less chances to error and No chances to failure.


Loader is a program that loads machine codes of a program into the system memory.It is part of the OS of the computer that is responsible for loading the program. It is the bare beginning of the execution of a program. Loading a program involves reading the contents of executable file into memory. Only after the program is loaded the operating system starts the program by passing control to the loaded program code. All the OS that support loading have loader and many have loaders permanently in their memory.

To understand a little more check it out in this source:

By Gladys Nader

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