← Preprocessor and CompilationC PROGRAMMING 1.6.E
Linking & Libraries
Static vs dynamic linking and how the linker resolves symbols.
The last stage of the compilation pipeline from 1.1.A, expanded: how the linker actually resolves a function call to a real address, and the static-vs-dynamic choice for library code.
| Kind | File | How it works |
|---|---|---|
| Static library | .a | code gets copied directly into the final executable at link time — bigger binary, no runtime dependency |
| Dynamic/shared library | .so | the executable just records that it needs the library; the actual code gets loaded and linked at runtime |
Every function call in an object file starts as a symbol reference — a name, not yet an address. The linker's whole job is walking every object file and library being linked, finding where each referenced symbol is actually defined, and patching in the real address. "Undefined reference" errors are exactly this step failing — a symbol was called but never found defined anywhere in the link.
Notes from readers
Comments — via GitHub