T09 Dec 18, 2025 2 min read

Linking

The step that combines compiled pieces and libraries into a final binary by resolving references between them.

Definition

Linking is the step that combines compiled pieces of code (and libraries) into a final binary by resolving references between them.

If one piece says “call function X”, linking is where “X” is matched to the actual implementation that will be used.

  • Related: linker, loader, dynamic linker, shared library, symbol, relocation
  • Neighbor steps: compilation and producing an artifact

What linking actually does (conceptually)

Linking typically involves:

  • resolving symbols (names of functions/variables) to actual addresses
  • laying out code and data into a final file structure
  • applying relocations (fixing up address-dependent references)
  • recording dependency information for dynamic loading (when applicable)

A useful analogy

If compilation turns each source file into a “chapter”, linking is the bookbinding step: it assembles chapters and references into one volume, and it produces the table of contents that says where each referenced thing actually lives.

Static vs dynamic linking (high level)

Linking can produce different shapes of deliverables:

  • Static linking: dependencies are included into the resulting binary, producing a more self-contained artifact.
  • Dynamic linking: the executable depends on shared libraries that are loaded at runtime by the OS loader/dynamic linker.

Both approaches have tradeoffs around size, startup time, update/patch behavior, and “dependency present at runtime” failure modes.

Why linking matters operationally

Many failures that look like “the program is broken” are actually linking/loader problems:

  • unresolved symbols (missing dependency or incompatible versions)
  • the wrong architecture (binary built for a different CPU)
  • missing shared libraries in the runtime environment
  • incompatible ABIs between compiled components

Mini-scenario

An executable is built on one machine where a shared library is present. It starts fine locally. In production, the same executable fails immediately because the runtime environment doesn’t contain a compatible version of that library. The code didn’t change. The environment and dynamic linking expectations did.

Linking in the source → artifact pipeline

Source code is translated by compilation into compiled pieces. Linking turns those pieces into a shippable artifact (often an executable or shared library) that can become a running program.