- 2073 Shrawan · 4 marks
Compilation, linking and loading process
Short answer
A C program goes through preprocessing, compilation (source to object code), linking (object code combined with libraries into an executable), and loading (copying the executable into RAM to run). For example, hello.c becomes hello.o, then hello.exe, and loading displays Hello.
Explain the program compilation, linking and loading process with example.
After it is written (edited), a C program goes through four stages before it runs: preprocessing, compiling, linking and loading.
Source --> Preprocessor --> Compiler --> Object
(prog.c) (#include, (prog.o)
#define) |
v
Running <-- Loader <-- Executable <-- Linker <-- Libraries
process (RAM) (prog.exe) (stdio, math)
- Preprocessing: directives such as
#include <stdio.h>and#defineare processed. - Compilation: the compiler checks syntax and converts the source into machine-level object code. Syntax errors are reported here.
- Linking: the linker joins the object code with library code (for example, the code of
printf) and creates the executable file. - Loading: the loader copies the executable from disk into main memory and starts execution at
main().
Example: for hello.c containing printf("Hello");, compiling gives hello.o, linking with the C library gives hello.exe, and running it loads the file into RAM and displays Hello.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Copy string converting lower to upper using pointer · Computer Programming, chapter 9 · asked 3×
- COM vs EXE; assembling, linking, executing · Microprocessor, chapter 3