Dear LJ Genie: I am in linker hell

May 22, 2009 18:57

I'm building a C++ project for an unusual platform, and am having some confusing problems with my libstdc++. For some reason which I cannot fathom, I am getting an absurd number of "undefined reference to..." linker errors for symbols which are indeed undefined in libstdc++.a, but which are definitely defined in libc.a and libgcc.a. Yes, I am ( Read more... )

lj genie, code, busy busy busy

Leave a comment

Comments 20

feonixrift May 22 2009, 17:09:11 UTC
First thought: Library paths.

Reply

maradydd May 22 2009, 17:13:40 UTC
All as they're supposed to be. libstdc++.a and libc.a are in the same directory, and ld is complaining about an undefined reference to vsprintf, which is defined in libc.a. Cf. also earlier, rectified issue with libgcc.a.

Reply

feonixrift May 22 2009, 17:35:01 UTC
Mixing C and C++ headers like that set off "here be complicated" flags, so I went looking for summaries, since my c++ is rusty.

This matches my impression of the munging involved: http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html

Reply

maradydd May 22 2009, 17:38:06 UTC
The wacky thing is, this is a pure C++ project. I think something about the way libstdc++ was compiled for this platform requires me to manually link in some C libraries (see speculation below about an incomplete libstdc++.la). Cross-compiling is such a headache.

Reply


tangaroa May 22 2009, 17:15:16 UTC
Try changing the order in which you link the files in the g++ command. As absurd as it sounds, that once worked for me.

Reply

maradydd May 22 2009, 17:24:13 UTC
I've had that happen before with other projects, though usually what solves it is putting the libraries with the necessary dependencies first, and right now the order is -lgcc -lc -lstdc++. I'll try putting -lstdc++ first and see if that gets me anywhere. Will report shortly.

I am, however, noticing that libstdc++.la doesn't specify libc.a as a dependency ... wondering if that might have something to do with it.

Reply

maradydd May 22 2009, 17:28:06 UTC
Well, for crying out loud, putting -lstdc++ first did it. Thanks!

Reply

vatine May 22 2009, 18:52:07 UTC
The reason is that the linker doesn't record where it last saw any specific (not yet needed) function/variable, so libraries must be linked in "reverse" dependency order (that is, if object file A depends on obnject file B, they either have to be in the same archive OR object file A must be processed before object file B).

Ugh, the cruft the brain picks up over the years.

Reply


(The comment has been removed)

maradydd May 22 2009, 17:38:27 UTC
Amen to that one.

Reply


patrickwonders May 22 2009, 22:47:46 UTC
This reminds me of a question we used to have on our "grill the programmer" interview questions at Xerox: why might a library appear on a link line more than once?

Sunpro fixed it. Apparently gcc has not.

Reply


allonymist May 23 2009, 01:13:18 UTC
Ha! I ran into this in 2007:
http://allonymist.livejournal.com/9639.html

Reply


Leave a comment

Up