How to use delay loading with a DLL that exports C++ classes(如何对导出 C++ 类的 DLL 使用延迟加载)
问题描述
我有一个 DLL one.dll,它使用通过 class __declspec(dllexport) 从 two.dll 导出的类 TwoClass代码>.我希望 one.dll 将 /delayload 用于 two.dll,但出现链接错误:
I have a DLL one.dll that uses a class TwoClass exported from two.dll via class __declspec(dllexport). I'd like one.dll to use /delayload for two.dll, but I get a link error:
LINK : fatal error LNK1194: cannot delay-load 'two.dll' due to import
of data symbol '"__declspec(dllimport) const TwoClass::`vftable'"
(__imp_??_7TwoClass@@6B@)'; link without /DELAYLOAD:two.dll
这是在发布版本中;在调试版本中它可以工作.(我不知道 Release 和 Debug 在 vtable 导出方面有什么区别,也找不到任何编译器开关或 pragma 来控制它.)
That's in a Release build; in a Debug build it works. (I don't know what the difference is between Release and Debug in terms of vtable exports, nor can I find any compiler switches or pragmas to control it.)
如何将 /delayload 与在发布版本中导出此类的 DLL 一起使用?
How can I use /delayload with a DLL that exports classes like this in a Release build?
推荐答案
看看 这里,看来此人遇到了完全相同的问题并找到了解决方法
Have a look here, seems that the person had exactly the same problem and found a workaround
我设法延迟加载通过禁用对发布版本的优化来工作使用 SomeClass 类的翻译单元 - 不知何故它带走了对导出的 vtable 的依赖.
I managed to get the delay loading to work in release build by disabling the optimizations on the translation unit that was using SomeClass class - somehow it took away the dependency on exported vtable.
这篇关于如何对导出 C++ 类的 DLL 使用延迟加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何对导出 C++ 类的 DLL 使用延迟加载
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
