链接器故障:如何确定“/DEFAULTLIB"的位置来自 [英] Linker Trouble: How to determine where a "/DEFAULTLIB" is coming from

查看:35
本文介绍了链接器故障:如何确定“/DEFAULTLIB"的位置来自的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种好方法来确定链接时哪个模块导致某个库被处理为/DEFAULTLIB",如 Visual Studio 的详细链接器输出所示.

I am trying to find a good way to determine what module at link time is causing a certain library to get processed as a "/DEFAULTLIB" as seen in the verbose linker output from Visual Studio.

这是我的情况,我有几个静态库先决条件,每个都有一个发布版本和一个调试版本(BlahD.lib 和 Blah.lib).由于某种原因,在链接时,所有 *D.lib 都作为默认库处理,即使我正在构建一个带有指定为附加依赖项"的非调试库的版本.如果我从不构建静态库的调试版本,那么这些 *D 文件将不存在,并且会出现链接器错误(无法打开文件).

Here is my situation, I have several static library pre-requisites and each has a release and a debug version (BlahD.lib and Blah.lib). For some reason at link time all of the *D.lib's are processed as default libraries even though I am building a release with the non-debug libs specified as "Additional Dependencies". If I never build the debug versions of the static libraries those *D files wouldn't exist and there would be a linker error (can't open file).

我可以通过为所有这些有问题的 .lib 文件指定/NODEFAULTLIB 来成功构建我的项目.所有的发布库链接起来,每个人都很高兴.但我想了解这里发生了什么.是什么导致链接器处理这些 *D.lib 文件?我唯一的希望是编写某种脚本来转储这个庞大项目及其相关项目(microsoft 支持)中的所有内容吗?即使这样,我也不明白要在 dumpbin 输出中查找什么,这是否适用于 .lib 文件以及 .obj 文件?

I can get my project to build successfully by specifying /NODEFAULTLIB for all of these offending .lib files. All the release libraries link up and everyone is happy. But I want to understand what is going on here. What is causing these *D.lib files to be processed by the linker? Is my only hope to write some kind of script that dumpbins everything in this massive project and its dependant projects (microsoft support)? Even then I don't understand what to look for in the dumpbin output, does this apply to the .lib files as well the .obj files?

推荐答案

寻找 #pragma comment(lib) 在源代码中.查看它是否可能依赖于 #define - 这是 SDK 确保链接正确库的常用方法,您可能需要定义 THESDK_DEBUGTHESDK_RELEASE 用于解决逻辑.

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.

附加信息:我在 Visual Studio 2008 中发现,即使注释掉 *.idl 文件中的语句不起作用,如:

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")")

编译器仍将 MYLIB.lib 添加为 DEFAULTLIB,并在 *.obj 文件中结束.确保从代码中完全删除该行!

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!

这篇关于链接器故障:如何确定“/DEFAULTLIB"的位置来自的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆