简体   繁体   English

DLL依赖关系并允许其失败

[英]DLL dependencies and allowing one to fail

I am currently looking at an issue where a project is generating a DLL. 我目前正在研究一个项目正在生成DLL的问题。 Now it is built upon a chain of other projects which are all C++, so they're just .lib files being linked in. 现在,它是基于一系列都是C ++的其他项目构建的,因此它们只是链接到的.lib文件。

In this case one project uses OpenCL, however I don't believe those code paths are being run. 在这种情况下,一个项目使用OpenCL,但是我不认为这些代码路径正在运行。 However it would appear that just having OpenCL linked in causes the output .DLL to have a dependency on OpenCL.dll. 但是, 似乎只有链接OpenCL会导致输出.DLL对OpenCL.dll具有依赖性。

Please correct me if I am wrong here (in which case I'll go over the code with a fine-toothed comb to ensure no OpenCL calls are being executed). 如果我错了,请纠正我(在这种情况下,我将使用细齿梳检查代码,以确保没有执行OpenCL调用)。

I am not sure how Visual Studio (or dependency walker?) figures out which DLL's are dependencies for a given DLL. 我不确定Visual Studio(或依赖项遍历器)如何找出哪个DLL是给定DLL的依赖项。 However I don't want the OpenCL.dll dependency. 但是我不想要OpenCL.dll依赖项。

What are my options? 我有什么选择?

One possible one is to take the project with the OpenCL code and refactor so some portion of it can be build with the OpenCL portion excluded from the build. 一种可能的方法是使用OpenCL代码处理项目并进行重构,以便可以使用不包含在构建中的OpenCL部分进行构建。 However this will be a fair chunk of work so I am really hoping for something simpler. 但是,这将是相当大的工作,因此我真的希望有一些简单的方法。

If you link a lib you depend on the dll . 如果链接lib ,则取决于dll The easiest thing for you would be to add /DELAYLOAD for this dll : 对您来说,最简单的方法是为此dll添加/DELAYLOAD

The /DELAYLOAD option causes the DLL that's specified by dllname to be loaded only on the first call by the program to a function in that DLL. / DELAYLOAD选项使由dllname指定的DLL仅在程序第一次调用该DLL中的函数时才加载。

This generates a 'soft' dependency which only kicks in if you call a function that actually needs the DLL. 这将生成一个“软”依赖项,仅当您调用实际上需要DLL的函数时,该依赖项才起作用。 Make sure you read Constraints of Delay Loading DLLs . 确保您阅读了延迟加载DLL的约束

The other option (which I don't recommend) is to use runtime binding via LoadModule and GetProcAddress , then invoke functions via the pointer to function. 另一个选择(我不推荐)是通过LoadModuleGetProcAddress使用运行时绑定,然后通过指向函数的指针调用函数。 This removes any dependency, but you are tasked to implement all check, all errors if the DLL is missing, and it can easy go astray if you mismatch the function signature/call convention. 这消除了任何依赖关系,但是您的任务是实施所有检查,如果缺少DLL,则执行所有错误,如果不匹配功能签名/调用约定,则很容易误入歧途。 Ultimately, you'd be implementing /DELOAYLOAD manually. 最终,您将手动实现/DELOAYLOAD

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法加载x.dll或其依赖项之一 - Couldn’t load x.dll or one of its dependencies 有没有办法排除DLL依赖项 - Is there a way to exclude DLL dependencies 具有可选依赖项的ctypes DLL - ctypes DLL with optional dependencies 具有NuGet依赖项的参考DLL - Reference DLL with NuGet dependencies 无法加载文件或程序集'quickfix_net.dll'或其依赖项之一 - could not load file or assembly 'quickfix_net.dll' or one of its dependencies VS2017 无法加载文件或程序集 Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 或其依赖项之一 - VS2017 Could not load file or assembly Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll or one of its dependencies “Detected Dependencies”文件夹中的重复DLL - Duplicated DLL in the “Detected Dependencies” folder Visual Studio DLL参考依赖 - Visual Studio DLL reference dependencies IBM DB2 问题--System.BadImageFormatException:无法加载文件或程序集 IBM.DB2.DLL 或其依赖项之一 - IBM DB2 issue--System.BadImageFormatException: Could not load file or assembly IBM.DB2.DLL or one of its dependencies 站点无法运行 - 无法加载文件或程序集“dtSearchNetApi4.DLL”或其依赖项之一。 指定的模块无法找到 - Site won't run - Could not load file or assembly 'dtSearchNetApi4.DLL' or one of its dependencies. The specified module could not be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM