Learning path

Full curriculum

Full curriculum

Unit content

Object files, symbols and linking

Compiling one source file need not produce a complete executable. Toolchains commonly produce an object file containing machine code, data and metadata whose external references are not yet fully resolved.

Symbols

A symbol names a function, global object or other linkable entity. One object file can define a symbol while another contains an unresolved reference to it.

Linking

The linker combines object files and libraries, matches references with definitions, lays out code and data, and applies relocations so addresses are correct in the combined output.

source files
   ↓ compile
object files + libraries
   ↓ link
executable or shared library

Static libraries

A static library is an archive of object code that the linker can copy into the final linked result when needed.

Linker errors

An undefined-reference error means a required symbol was not supplied by the linked inputs. A multiple-definition error means incompatible definitions compete for the same symbol.

These are later-stage problems than syntax or type errors: each individual translation unit may have compiled successfully before the link fails.