Chapter 17: Binary Linking & Libraries

In OS development, how a program connects to its helper functions defines its portability. This process is called Linking. As an Architect, you must choose between Static and Dynamic linking based on your system goals.

1. Static vs. Dynamic Linking

Static Linking: All required library code is copied into the final binary.
Pro: Highly portable; works in any environment.
Con: Larger file size.

Dynamic (Shared) Linking: The binary only contains references to libraries (like libc.so).
Pro: Saves memory and storage.
Con: Fails to run if the library is missing.

2. Investigating Binaries with 'ldd' and 'readelf'

To see what "bloodline" or dependencies a program has, we use standard Linux diagnostic tools.

# Check shared library dependencies
$ ldd /bin/ls

# Deep dive into the ELF (Executable and Linkable Format) header
$ readelf -h ./my_compiled_binary
Architect's Insight: For a mobile-first OS built in Termux, using Static Linking for core system tools is often safer to avoid "Library Mismatch" errors when switching between Android versions.