Why would the order of linking libs cause runtime errors?
I have an unmanaged C++ project, which produces runtime errors when the linker libraries (Properties->Linker->Input->Additional Dependencies) are listed in a specific order but runs fine when I change the order of libraries. I understand why the order could cause Link errors (Why does the order in which libraries are linked sometimes cause errors in GCC?) but how could it possibly cause runtime errors? I observed this in VS2005, 2008 and 2010.
What kind of runtime errors? You don't say, so we have to guess.
Here's one way a runtime error could happen: If two unrelated libraries expose different functions that happen to have the same name, the linker will pick the first implementation it finds.
If you intended to call draw()
from paint.lib
, but gunfight.lib
is earlier in the linker list, you will be calling the wrong draw()
with unpredictable consequences.
下一篇: 为什么连接库的顺序会导致运行时错误?