tags:

views:

148

answers:

1

Hello,

This is a follow up to an earlier question -

http://stackoverflow.com/questions/1227615/how-to-use-a-different-stl-with-g

I can now get my code to build while using a different STL. However, I still need to link -lsupc++ (along with said different STL)

I see anecodal references that -lsupc++ should be the last library on the link line. I cannot find a definitive answer to this. Currently, it is not the last library on the link line for me and things seem to work fine.

Thanks!

+4  A: 

Link line ordering is a picky, cranky thing. The rule is that libraries have to be linked in reverse dependency order: if object A is in libfoo, and depends on object C from libbar, then the link line needs to go -lfoo -lbar and not the other way around. Having -lsupc++ at the end makes sure that if any other libraries you're linking depend on objects in libsupc++, the dependency will resolve correctly. In your case, the trailing libraries probably just don't have any unresolved dependencies.

Meredith L. Patterson
Good advice. But some versions of ld are so primitive that you will actually have to name the library twice on the command line to resolve circular dependencies.
anon
Wow. I've never run into one of those, and God willing I never will, but this is good to know. Thanks!
Meredith L. Patterson
Thanks a lot guys. I now understand a little bit more about this whole linking game :) btw, I assume that this ordering matters only when you have a static library in the menagerie (i.e. supc++) ? i.e. if there were only dynamic libraries, then the ordering should not matter?
MK
My understanding is that it matters regardless.
Meredith L. Patterson