quantecon_nyu_2016 icon indicating copy to clipboard operation
quantecon_nyu_2016 copied to clipboard

Steps that GCC goes through to compile a Linux C Program

Open mmcky opened this issue 9 years ago • 0 comments
trafficstars

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/

mmcky avatar Feb 12 '16 16:02 mmcky