Linker Trouble: How to determine where a “/DEFAULTLIB” is coming from

做~自己de王妃 提交于 2019-12-05 00:56:10
Erik

Look for #pragma comment(lib) in the source. See if it perhaps is dependent on a #define - This is a common way for a SDK to ensure that the right libs are linked, and you may need to define THESDK_DEBUG or THESDK_RELEASE for the logic to work out.

Additional information: I discovered in Visual Studio 2008 that even commenting out the statement from the *.idl file does not work, as in:

//cpp_quote("#pragma comment( lib, \"MYLIB.lib\")")

The compiler still adds MYLIB.lib as a DEFAULTLIB, and it winds up in the *.obj file. Make sure you remove the line completely from the code!

Yodan Tauber

I had a similar problem. I was only able to solve it by analyzing the *.obj files as you suggested. To do it, I ran the following command via the Visual Studio command prompt (in the temp folder of the project, where *.obj files are generated):

for /R %1 in (*.obj) do @dumpbin /directives /section:.drectve "%1" > "%1".directives.txt

Then I used Notepad++ to search for the name of the offending library in all of these *.directives.txt files. This revealed which project was referencing the wrong lib.

Note: you may want to modify this to include any 3rd-party *.lib files your project may use, and not just *.obj files. "/DEFAULTLIB" directives may also come from them.

Note: you may need to use *.o instead of *.obj

Link with the /verbose option and search the output for the name of the library in question. This will tell you which object file dragged the library into the link.

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