From: Alexandre P. N. <al...@om...> - 2006-08-24 16:59:48
|
Heilpern, Mark escreveu: > I've solved this, but I would like to know if there's a more robust > solution. > > The problem apparently is with the order of things on the link line -- > you can see I have my -l's appearing before the .o's. If I place the > .o's first I don't have the unresolved references. > > Is there a better way to do things, which doesn't result in command > line ordering requirements? The linker is sensitive to object order in command line, that's not exactly unavoidable but the tricks used to contorn it may turn linking a bit slower and prone to some very rare mistakes. the recommended order is: <linker and parameters> <objects in dependency order> <libraries in dependency order> The linker solves dependencies from left to right, meaning that the objects which depends on others must come to the left of (I mean, be mentioned before) those that provides the symbols for solving these dependencies. That's specially truth for static libraries, because that's a bunch of object files with an index, and that index is checked only once. Dynamic libraries are resolved at run time, so it's mutual-dependency are not exactly dependent on the order they're passed at link time, though that may influence the lazy object resolval (If you use pthread and explictly mention libc, -lpthread should appear before -lc at least once). I suggest you write a Makefile for your program, something like: program_objects := obj1.o obj2.o obj3.o # ... and so on. program_libraries := -llibone -llibtwo # ... and so on program: $(program_objects) $(LD) $^ $(program_libraries) -o $@ That way you will not need to remember the correct order more than once ... - Alexandre |