Finding Unresolved Link References on the Mac/Gnu
Posted by rickb on 5th February 2008
I recently built a third party source on the Mac, only to find it had a number of unresolveds (link errors.)
If you build in XCode, the tool is kind enough to tell you what’s referencing the unresolved(s). From the commandline, it’s not so obvious.
Since this is third party code, I don’t want to have to go through the hassle of building an XCode project — but I need to find out which modules were referencing the link unresolveds.
Finally, after a bit of head-scratching, I got the solution — so I can share it, here, if you’re unlucky enough to be searching for this needed capability:
The Solution – Getting the Module/Filename That References the Unresolved
You need to enable a link flag ‘-y’, followed by the unresolved symbol (you’ll get that from the failed link output.) Go into the Makefile and find LDFLAGS (’ld’ is the gnu linker — this is the typical Makefile variable for the options) and add the ‘-y’ flag, followed by the symbol, like this:
LDFLAGS = -y__2435ZClass5FunctioniiiEi [rest of options]
Some of the symbols can get quite long — make sure you paste and copy the whole thing, including the leading underscores. Next time you do a build, the link step will output a line as to what module in your project references that symbol (yay.)
Your work’s not necessarily over — the lib I was building uses a very complex class hierarchy, and it wasn’t apparent which lines of code were causing the unresolved, even though I knew what file it was happening in. If that’s the case, then what I do is selectively #ifdef out parts of the file until I can make the unresolved symbol appear and disappear in subsequent links. Then I can narrow it down to the offending line and fix it. (You get a whole bunch of other unresolveds as you comment out sections of the code — ignore those, of course.)
Tedious, but it works.
I imagine the same would apply in a linux/bsd environment — anything that’s using the Gnu toolsuite.
rickb
Posted in C++, Mac, MacIntosh, Open Source, Programming, Software Development | No Comments »
