This seems to be a question from a ancient time.
Imagine, we have a executable named juggle who has the following dependency:
juggle → libfoo.a → libbar.a
Then, we must write link command like this:
g++ -o juggle juggle.cpp -lfoo -lbar
but NOT:
g++ -o juggle juggle.cpp -lbar -lfoo
This problem exists as well when linking a .so (libpickle.so for example) . If you write lib list improperly, bar's code will not get into pickle but the link succeeds. Only when you try to dynamic load libpickle.so will you realize you have missed bar.
That is an over simplified example. In real world I constantly face so many libraries(many from our own team) to link and remembering lib dependency order can be a burden. I say "burden" because there is some other compiler(Visual C++) who don't put this burden on us.
So, I think it is best practice to always write linker component twice,
g++ -o juggle juggle.cpp -lfoo -lbar -lfoo -lbar
and, this also works when circular dependency exists.
Does anyone have the same idea with me, or, a better solution?
EDIT: I finally realize merely writing linker component twice does not necessarily make linking success. Assume a dependency of A -> B -> C , and we list library in order of C B A, we have to write C B A three times.