GCC Compilation Process

Compile

The GNU Compiler Collection (GCC) is having the capability of handling nearly 16 programming languages. Here we will see the steps involved in converting a C Program file into binary executable file. In GCC (and most of standard compilers), 4 major steps are followed (see the image).

Normally we use this command to compile a simple program:
$ gcc -Wall prog.c -o prg.bin

This simple command can sub devided into following 4 steps:

1: In preprocessing (cpp), header files and macros are processed.
$ gcc -E prg.c -o prg.i

2: In Compilation (gcc, c99-gcc, c89-gcc), the preprocessed file will be converted to assembly language.
$ gcc -S prg.i -o prg.s

3: In Assembling (gas), the assembly language program is converted to object file.
$ gcc -c prg.s -o prg.o

4: In Linking (ld), the object file is linked with standard and other external libraries.
$ gcc prg.o -o prg.bin

From the above commands, it looks like GCC is doing all operations. But GCC use some other external programs (cpp, gcc, gas, ld) to complete this tasks.You can find this using the following option:
$ gcc -v -save-temp prg.c -o prg.bin

Advertisements
Tagged with: ,
Posted in Uncategorized

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

%d bloggers like this: