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


- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 从python回调到c++的选项 2022-11-16
- STL 中有 dereference_iterator 吗? 2022-01-01
- C++ 协变模板 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01