如何使用导出C ++类的DLL的延迟加载 [英] How to use delay loading with a DLL that exports C++ classes

查看:738
本文介绍了如何使用导出C ++类的DLL的延迟加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DLL one.dll 使用从两个导出的类 TwoClass .dll 通过 class __declspec(dllexport)。我想要 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

在Debug构建它工作。 (我不知道在vtable导出方面Release和Debug之间有什么区别,也不能找到任何编译器开关或pragmas来控制它。)

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的延迟加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆