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