5.3.5 · D3Build Systems & Toolchain

Worked examples — Symbol resolution — order matters

2,307 words10 min readBack to topic

Quick reminder of the three sets, because every trace below uses them:

Recall The three sets (from the parent)

::: the set of object files that will go into the final executable. ::: the set of symbols used but not yet defined — "still needed." ::: the set of symbols already defined by something in . The linker's goal ::: make empty by the time the command line ends.


The scenario matrix

Think of the "inputs" to symbol resolution as a few independent knobs. Every real link is one combination of these knobs. The table below lists the knob-settings ("cells") that behave differently — those are exactly the cases we must cover so you never meet an unshown scenario.

Cell Situation Does it link? Example
A Object needs a symbol, provider library is after it ✅ works Ex 1
B Same symbols, library placed before the object (wrong order) ❌ fails Ex 2
C Library present but symbol never referenced (member dropped) ✅ links, but code silently absent Ex 3
D Circular dependency between two static archives ❌ / needs group Ex 4
E Two strong definitions of the same symbol ❌ multiple definition Ex 5
F One strong + one weak definition ✅ strong wins silently Ex 6
G Symbol has no definition anywhere (degenerate / empty provider) ❌ undefined reference Ex 7
H Shared library (.so) with --as-needed, listed before its user ❌ dropped Ex 8
I Real-world word problem: multi-library app, find the correct order ✅ once ordered Ex 9
J Exam twist: three libraries, transitive chain, predict success/failure ⚠️ predict Ex 10

The two "knobs" that create all this variety are (1) position of a provider relative to its user, and (2) definition count (0, 1 weak, 1 strong, 2 strong, 1 strong + weak). The figure below is the mental model — a one-way hallway — that every cell is a variation of.

Look at the red arrow: it only moves rightward. A locker (archive) behind the arrow can never be revisited. That single fact generates cells A–J.


Cell A — provider after user (the correct order)


Cell B — provider before user (the classic failure)


Cell C — symbol never referenced (member silently dropped)


Cell D — circular static libraries


Cell E & F — definition count (two strong vs strong+weak)


Cell G — no definition anywhere (degenerate)


Cell H — shared library, --as-needed, wrong order


Cell I — real-world word problem


Cell J — exam twist (predict first)



Connections