The order of linking and unresolved symbols
A linker can often seem whimsical and start complaining about things for no apparent reason. This is an especially difficult ordeal for programmers starting out who don't know their way around this tool. It's no wonder, since they usually try to avoid touching build configuration for as long as they possibly can. Eventually, they're forced to change something (perhaps add a library they worked on) in the executable, and all hell breaks loose.
Let's consider a fairly simple dependency chain – the main
executable depends on the outer
library, which depends on the nested
library (containing the necessary int b
variable). Suddenly, an inconspicuous message appears on the programmer's screen:
outer.cpp:(.text+0x1f): undefined reference to 'b'
This isn't such a rare diagnostic – usually, it means that we forgot to add a necessary library to the linker. But in this case, the library...