C compilation process

C compilation process

What is GCC?

The GNU Compiler Collection, commonly known as GCC, is a set of compilers and development tools available for Linux, Windows, various BSDs, and a wide assortment of other operating systems. It includes support primarily for C and C++ and includes Objective-C, Ada, Go, Fortran, and D. The Free Software Foundation (FSF) wrote GCC and released it as completely free (as in libre) software.

Command to compile

gcc <file.c>
        

Process

No hay texto alternativo para esta imagen


Preprocessing:

he C compilation begins with pre-processing of source file, in this step the comments are removed, include headers and expand macros 


gcc -E main.c > main
        

Compilation:

In this stage, the preprocessed code is translated to assembly code that is specific to the operating system.


gcc -S main.c > main.s
        

Assemble:

In this stage, an assembler translates the assembly instructions to object code to be run by the OS.


gcc -c main.c > main.o
        

Linking:

In this stage, the processor has to link pieces of the program that are missing or out of order. By “linking” all these functions together, the result is a final executable program.


gcc main.c -o myexecutablefile
        


To view or add a comment, sign in

More articles by Benjamín Gutierrez

  • Recursion

    What is Recursion? The process in which a function calls itself directly or indirectly is called recursion and the…

  • Class and instance attributes | Python

    A class is a user-defined blueprint or prototype from which objects are created. Classes provide a means of bundling…

  • What happens when you type 'ls -l *.c' in the shell

    When we type 'ls -l *.c' and hit 'Enter' what happens is that all files that end with ".

  • Two's complement and negative numbers

    Negative Signed Binary Numbers: In the binary system we do not have a minus sign to represent a negative number. For…

  • Hard links and Symbolic links

    Hard links and symbolic links are two different methods to refer to a file in the hard drive. INode is the data file…

Explore content categories