Download presentation
1
Lecture-1 Compilation process
2
C Compilation process Components of Compiler Preprocessor Compiler
Source code( .c file) Preprocessor Compiler Assembly code Components of Compiler Assember Libraries Object code Linker Executable file
3
Preprocessor /* this is demo */ #include<stdio.h> void main() {
printf (“hello”); } Preprocessor code of stdio.h file void main() { printf (“hello”); } Preprocessor remove comments and include header files in source code, replace macro name with code.
4
Compiler code of stdio.h file void main() { printf (“hello”); }
push ebp mov ebp, esp and esp, -16 sub esp, 16 mov eax, OFFSET FLAT:.LC0 mov DWORD PTR [esp], eax call printf leave ret Compiler generate assebmly code.
5
Assembler push ebp mov ebp, esp and esp, -16 sub esp, 16 mov eax, OFFSET FLAT:.LC0 mov DWORD PTR [esp], eax call printf leave ret Assembler Assebler convert assemble code into object code.
6
Linker Libraries Linker
7
Linker: Static linking
one() #include<stdio.h> void main() { one(); } Libraries Call function one() Linker Code of function one included in final executable file.
8
Linker: Static Linking
Code of file 1 calling 200 funtions. Code of file 2 calling 100 functions. Libraries Object file1 Object file2 Linker Size ?
9
Linker:Static Linking
1 exe file generated. 4 Again compilation needed so that exe file include updated one function. 2 User take exe file. 3 Some changes made in one function. Libraries 010100
10
Linker: Dynamic linking
one() #include<stdio.h> void main() { one(); } Libraries Call function one() 0x2EA126 One function Library Linker Address of one function in memory Memory address, where one function is loaded , included in final executable file. Memory
11
Linker: Dynamic Linking
Benefits over static linking Size No need to compile
12
Library Static Library Dynamic Library Windows .lib (Library)
Linux .a (Archive) Dynamic Library Windows .dll (Dynamic link library) Linux .so (Shared object)
13
Commands Linux (gcc) Preprocessor step ( gcc -E <filename>)
Compiler step( gcc -S <filename>) Generate Object code(gcc -O <filename>) Generate executable (gcc <object code>)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.