Skip to content

Steps that GCC goes through to compile a Linux C Program #11

Open
@mmcky

Description

@mmcky

Information for Interested Students

There are generally considered 4 phases to GCC compilation for C programs in Linux

  1. Pre-Processing
  2. Compilation
  3. Assembly [Shown in Class]
  4. Linking

The pre-processing stage the text file that you have written is pre-processed to strip unnecessary information such as comments. It also processes any include statements etc.

The compilation stage converts the output of pre-processing and is responsible for converting it to an assembly layer. In this process the compiler is responsible for doing a lot of work and perform various optimizations in generating the assembly code

The assembly stage converts the assembly into object level code.

The linking stage manages the linking requirements to external calls such as printf.

You can actually see these steps using -save-temps option during compilation.

gcc -Wall -save-temps print.c -o print

There is a lot more to it under the surface - but this gives you a sense of the compilation process.

If you are really keen then here is some interesting reading:

  1. http://www.thegeekstuff.com/2011/10/c-program-to-an-executable/
  2. https://www.redhat.com/magazine/002dec04/features/gcc/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions