-
-
Save Rafat97/622ab1a8269f77891564cf1be6871c97 to your computer and use it in GitHub Desktop.
The main steps are -
1. Preprocessor :
The source code is the code which is written in a text editor and the source code file is given an extension ".c". This source code is first passed to the preprocessor, and then the preprocessor expands this code. After expanding the code, the expanded code is passed to the compiler.
2. Compiler :
The code which is expanded by the preprocessor is passed to the compiler. The compiler converts this code into assembly code. Or we can say that the C compiler converts the pre-processed code into assembly code.
3. Assembler :
The assembly code is converted into object code by using an assembler. The name of the object file generated by the assembler is the same as the source file. The extension of the object file in DOS is '.obj,' and in UNIX, the extension is 'o'. If the name of the source file is 'hello.c', then the name of the object file would be 'hello.obj'.
4. Linker :
Mainly, all the programs written in C use library functions. These library functions are pre-compiled, and the object code of these library files is stored with '.lib' (or '.a') extension. The main working of the linker is to combine the object code of library files with the object code of our program.
#include <stdio.h>
int main()
{
printf("Hello World\n");
getchar();
return 0;
}
Note This is tested on windows
1. Preprocessing :
$ gcc.exe -E C:\Users\rafat\OneDrive\Desktop\demo\hello.c -o C:\Users\rafat\OneDrive\Desktop\demo\hello.i
2. Compiler :
gcc.exe -S C:\Users\rafat\OneDrive\Desktop\demo\hello.c -o C:\Users\rafat\OneDrive\Desktop\demo\hello.s
3. Assembler :
$ gcc.exe -c C:\Users\rafat\OneDrive\Desktop\demo\hello.c -o C:\Users\rafat\OneDrive\Desktop\demo\hello.o
or
$ gcc.exe -C C:\Users\rafat\OneDrive\Desktop\demo\hello.c -o C:\Users\rafat\OneDrive\Desktop\demo\hello.o
4. Linker :
$ gcc.exe -o C:\Users\rafat\OneDrive\Desktop\demo\hello.exe C:\Users\rafat\OneDrive\Desktop\demo\hello.o
https://drive.google.com/file/d/1hw-O6pbcVV5MmpJTktPc5Z36Vt7VSLpQ/view?usp=sharing