Abstract

- Convert from C program to Instruction, then execute it as a Process (进程)
Important
We usually use
gccwhich stands for GNU Compiler Collection, a program that handles the 5 steps program compilation for us.
gcc -Wall program.ctells the C compilers to give all possible warnings.
Stage 1
gcc -E hello_world.c- Preprocessor generates expanded
.Ifile - Process Pre-processor Directives
- Replace all the Macro Expansion in the Header File & program files
- Would’t complain about missing Header File
- Is done by a program called
cpp Remove spaces, new lines & comments
Stage 2
gcc -S hello_world.c- Compiler generates codes in Assembly language in
.sformat - Returns error & warnings if the Header File isn’t defined
- Is done by a program called
cc1
Stage 3
gcc -c hello_world.c- Assembler generate Instruction in
.oformat - Essential for code sharing and dynamic linking in software development
- Is done by a program called
as
Stage 4
- Linker Link up with other Instruction which are dependencies of the program we wrote
- Sometimes we will break the program into many different
cfiles, then run compiler on each, and link up all. This is for easier management & debugging - Output executable format or library file
- We can use
lddto show the dependencies - Will return error if unable to link up some of the required
.ofiles - Is done by a program called
ld
Stage 5
- Loader loads the executable from Disk to Main Memory to create a Process (进程). This part is handled by the OS
References
- C Language Source Code to EXE
- [Modern OS - 1.8.3 Large Programming Projects](https://csc-knu.github.io/sys-prog/books/Andrew%20S.%20Tanenbaum%20-%20Modern%20Operating%20Systems.pdf#Large Programming Projects)
