是否允许在禁用 rtti 的应用程序中链接启用 rtti 的 DLL?

发布于 2024-08-01 16:24:16 字数 555 浏览 0 评论 0原文

我有一个解决方案来构建一个 DLL,并在其项目属性中启用运行时类型信息。 这是 Visual Studio 2005 中的默认值 (/GR)。在我们的库中,我们有很多dynamic_cast,因此我目前无法在没有运行时类型信息的情况下构建 DLL。

现在我的客户正在使用达索系统的开发工具,该工具声明他们不能使用运行时类型信息。 它始终处于禁用状态 (/GR-)。

问题是这是否有问题?

我用一个小例子尝试了这种情况,其中使用一些执行动态转换的代码创建了 DLL。 该 DLL 是在启用 RTTI 的情况下构建的。小型应用程序使用该 DLL,尤其是带有dynamic_casts 的代码。 此应用程序构建为 RTTI 禁用。 效果很好。 但是,由于不可预测的行为,任何事情都可能发生...

我想告诉我的客户,将 DLL 与其中一些使用 RTTI 和其他不使用 RTTI 的 DLL 混合不是问题,但我找不到有关它的详细信息(使用 Google, MSDN 等)。 有谁知道这个问题的答案?

I have a solution to build a DLL with run-time type information enabled in its project properties. This is the default (/GR) in Visual studio 2005. In our library we have a good few dynamic_casts, so I'm not able currently to build the DLL without run-time type information.

Now my customer is using development tools from Dassault Systèmes, which state they can not use Run-Time Type Information. It is disabled (/GR-) always.

The question is whether or not this is a problem?

I tried this situation with a small example in which a DLL is created with a bit of code doing dynamic casts. The DLL is built with RTTI enabled. A small application uses the DLL and especially the code with the dynamic_casts. This application is built RTTI disabled. It works fine. But with unpredictable behaviour anything can happen ...

I would like to tell my customer that mixing DLLs with some of them using RTTI and others not using RTTI is not a problem, but I couldn't find detailed information about it (using Google, MSDN, etc.). Does anyone know the answer to this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

固执像三岁 2024-08-08 16:24:16

是的,您可以,但有很大的限制。 其中一些:

  • 不要从DLL中传递任何异常,
  • 不要在非RTTI代码上使用dynamic_cast,
  • 通过比较DLL中类数组的大小,你可以得到奇怪的效果 sizeof(DllClass[10]) != sizeof(DllClass )*10
  • ...

在非 RTTI 环境中使用支持 RTTI 的 DLL 的最明显的例子 - 是 inproc OLE 服务器。 您可以使用任何选项开发 DLL,并将其嵌入到任何应用程序中。

Yes you can, but with very large of restrictions. Some of them:

  • don't pass any exception out of DLL,
  • don't use dynamic_cast on non-RTTI code,
  • You can get strange effect by comparing size of classes array from DLL sizeof(DllClass[10]) != sizeof(DllClass)*10
  • ...

The most bright example of usage RTTI enabled DLL in non-RTTI environment - is inproc OLE server. You can develop DLL with any options, that is embedded into any application.

北城半夏 2024-08-08 16:24:16

恕我直言,只要您不调用dynamic_cast,就不应该有问题。
虽然 Rtti 是一个非常简单的机制,但混合设置应该不会有什么坏处。
它可能只会伤害开发人员,因为他们忘记了这一点并编写了失败的代码。

大多数时候dynamic_cast都没有指出设计问题。

IMHO there shouldn't be a problem as long as you do not call dynamic_cast.
While Rtti is a very simple mechanism it shouldn't hurt to mix the setting up.
It may just hurt the developer who forgets about it and writes failing code.

Neither way most time dynamic_cast points to a design problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文