在GCC / Windows DLL / C ++ STL前面有什么改进? [英] Any improvements on the GCC/Windows DLLs/C++ STL front?

查看:101
本文介绍了在GCC / Windows DLL / C ++ STL前面有什么改进?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天,在Cygwin下使用GCC编译的DLL时,我遇到了一个令人讨厌的崩溃。基本上,一旦运行调试器,您可能会最终登陆到由RtlFreeHeap()接收到未分配的地址的调试陷阱中。



这是Cygwin的 GCC 3.4已知错误。出现这种情况是因为libstdc ++库对空字符串提供了一个聪明优化。我省略了详细信息(请参阅本文中的参考资料),但是只要在一个DLL中为一个属于另一个DLL的std :: string对象分配内存,最后给一个堆一个空闲的块另一堆。因此,RtlFreeHeap()中的 SIGTRAP。



当异常跨越DLL边界时,还有其他问题报告。



这使得GCC 3.4在Windows上是一个不可接受的解决方案,只要您的项目基于DLL和STL。我有几个选择可以通过这个选项,其中许多是非常耗时和/或恼人的:





我不能(还)切换到另一个编译器,因为我正在使用的其他一些工具。我从一些海湾合作委员会发现的意见是几乎从来没有报道过,所以这可能不是一个问题,这让我更烦恼了。



有没有人有一些关于这个的消息?我没有找到任何明确的声明,这已被修复(该错误仍被标记为分配),除了一个评论

谢谢!

$ b($)$ b b b b b b b b b b b b b b b b b b b b b b b b b b b $ b

解决方案

你遇到的一般问题是C ++从来没有真正意义上的组件语言。它真正用于创建完整的独立应用程序。诸如共享库和其他这样的机制之类的东西是由供应商自己创建的。想想这个例子:假设你创建了一个返回C ++对象的C ++组件。 C ++组件如何知道它将被C ++调用者使用?如果调用者是一个C ++应用程序,为什么不直接使用库?



当然,上述信息并没有真正帮助你。 b
$ b

相反,我将创建共享库/ DLL,以便遵循几个规则:


  1. 由组件创建的任何对象也被相同的组件销毁。

  2. 当所有创建的对象被销毁时,组件可以被安全地卸载。

您可能必须在组件中创建其他API以确保这些规则,但是遵循这些规则,它将确保不会发生像所描述的问题。 / p>

Yesterday, I got bit by a rather annoying crash when using DLLs compiled with GCC under Cygwin. Basically, as soon as you run with a debugger, you may end up landing in a debugging trap caused by RtlFreeHeap() receiving an address to something it did not allocate.

This is a known bug with GCC 3.4 on Cygwin. The situation arises because the libstdc++ library includes a "clever" optimization for empty strings. I spare you the details (see the references throughout this post), but whenever you allocate memory in one DLL for an std::string object that "belongs" to another DLL, you end up giving one heap a chunk to free that came from another heap. Hence the SIGTRAP in RtlFreeHeap().

There are other problems reported when exceptions are thrown across DLL boundaries.

This makes GCC 3.4 on Windows an unacceptable solution as soon as your project is based on DLLs and the STL. I have a few options to move past this option, many of which are very time-consuming and/or annoying:

I cannot (yet) switch to another compiler either, because of some other tools I'm using. The comments I find from some GCC people is that "it's almost never reported, so it's probably not a problem", which annoys me even more.

Does anyone have some news about this? I can't find any clear announcement that this has been fixed (the bug is still marked as "assigned"), except one comment on the GNU Radio bug tracker.

Thanks!

解决方案

The general problem you're running into is that C++ was never really meant as a component language. It was really designed to be used to create complete standalone applications. Things like shared libraries and other such mechanisms were created by vendors on their own. Think of this example: suppose you created a C++ component that returns a C++ object. How is the C++ component know that it will be used by a C++ caller? And if the caller is a C++ application, why not just use the library directly?

Of course, the above information doesn't really help you.

Instead, I would create the shared libraries/DLLs such that you follow a couple of rules:

  1. Any object created by a component is also destroyed by the same component.
  2. A component can be safely unloaded when all of its created objects are destroyed.

You may have to create additional APIs in your component to ensure these rules, but by following these rules, it will ensure that problems like the one described won't happen.

这篇关于在GCC / Windows DLL / C ++ STL前面有什么改进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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