The order of linking and unresolved symbols
The behavior of linker can sometimes seem capricious, throwing complaints seemingly without cause. This often becomes a particularly vexing challenge for novice programmers unfamiliar with the intricacies of this tool. Understandably, they often try to steer clear of build configurations for as long as possible. But there comes a time when they need to make a change—perhaps integrating a library they've developed—and all hell breaks loose.
Consider this: a relatively straightforward dependency chain where the main executable relies on an "outer" library. In turn, this outer library depends on a "nested" library that contains the essential int b
variable. Out of the blue, a cryptic error message confronts the programmer:
outer.cpp:(.text+0x1f): undefined reference to 'b'
Such errors are not particularly uncommon. Typically, they indicate a forgotten library in the linker. Yet, in this scenario...