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 使用延迟加载


基础教程推荐
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09