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 使用延迟加载
基础教程推荐
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- c++ STL设置差异 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
