Stages in Build Process

You write a C program, use gcc to compile it, and you get an executable. It is pretty simple. Right?

Have you ever wondered what happens during the compilation process and how the C program gets converted to an executable?

There are four main stages through which a source code passes in order to finally become an executable.

The four stages for a C program to become an executable are the following:

  1. Pre-processing
  2. Compilation
  3. Assembly
  4. Linking

ccompilerlinker001

Go Through these links listed below for more insight of the topic:
1. http://www.thegeekstuff.com/2011/10/c-program-to-an-executable/
2. http://www.tenouk.com/ModuleW.html

Important Points:
1. gcc -Wall -E print.c
   Using flag -E will print the preprocessed output to stdout.
2. gcc -Wall -save-temps print.c -o print
   ‘-save-temps’ flag instructs compiler to store the temporary intermediate files used by the gcc compiler in the current directory.
3. we compare the file sizes of both the print.o and print file, we’ll see the difference.

$ size print.o
   text	   data	    bss	    dec	    hex	filename
     97	      0	      0	     97	     61	print.o 

$ size print
   text	   data	    bss	    dec	    hex	filename
   1181	    520	     16	   1717	    6b5	print
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s