How linker solves ambiguities when linking *.libs?

爱⌒轻易说出口 提交于 2019-12-31 05:29:28

问题


after very long long time spent with unresolved externals I found that VS2010 was linking wrong .lib file.

Files were unfortunately named with same name.

Folder with linked(unwanted) lib was set in project properties Folder with unlinked(wanted) lib was inherited from other property sheet

Desired lib was newer date, undesired was very older.

Linker chose the unwanted one (as above).

What are the rules for linking libs? Shouldn't linker give at least warning on some ambiguity?

edit: symbol is defined ONLY in NEW lib. And the NEW lib is being searched only when I delete OLD lib (no linker settings changed)


回答1:


Think of LIBs to Linker as header to compiler. A LIB only has signature of exported symbols, unless it is static LIB. LIB files do not have any version attached to them.

Two LIB file can have same name, as two header files can have. It's you, the programmer, who has to use correct LIB/header file. If the linker doesn't find all symbols, or if symbols are not correct, it will report error (just like compiler will do for inconsistent symbols in header file).



来源:https://stackoverflow.com/questions/7043062/how-linker-solves-ambiguities-when-linking-libs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!