Skip to content
Latchkey

What Is a Linker? Joining Compiled Pieces Into a Program

A linker is the build tool that combines separately compiled pieces of code and libraries into a single runnable program, resolving the references between them.

Compilers usually translate each source file into a separate object file. None of those is a complete program; they reference functions and variables defined in other files or libraries. The linker is what stitches them together: it resolves every reference, lays out the final layout, and produces a single executable or library. Many build failures are actually link errors.

What the linker does

After compilation produces object files, the linker matches each reference (a call to a function, a use of a global) with its definition somewhere across all the objects and libraries. It then combines everything into one artifact with all addresses resolved.

Compiler vs linker

The compiler works on one source file at a time and does not know about other files. The linker works across all of them, which is why some errors (undefined or duplicate symbols) only appear at link time, after every individual file compiled fine.

Common link errors

  • Undefined symbol: a referenced function or variable has no definition.
  • Duplicate symbol: the same thing is defined in two places.
  • Missing library: a dependency was not provided to the linker.
  • Architecture mismatch: objects built for incompatible targets.

Static vs dynamic linking

The linker can copy library code directly into the executable (static linking) or leave references to be resolved at load time from shared libraries (dynamic linking). Each has trade-offs in size, startup, and how updates propagate.

A quick example

A program that calls a function declared but never defined will compile cleanly per file, then fail with an "undefined reference" error from the linker when it tries to combine everything.

The linker in CI

Link errors are deterministic build failures, missing symbols or libraries, that fail identically every run, so retrying never helps. They usually mean a misconfigured build or a missing dependency. Latchkey retries only transient infrastructure failures, leaving genuine link errors visible to fix.

Key takeaways

  • A linker combines compiled object files and libraries into a single program.
  • Link errors (undefined or duplicate symbols, missing libraries) appear after compilation succeeds.
  • They are deterministic build failures to fix, not transient failures to retry.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →