为什么全球本地对象引起C ++ / CLI中的DLL问题? [英] Why do global native objects cause problems in C++/CLI dlls?

查看:96
本文介绍了为什么全球本地对象引起C ++ / CLI中的DLL问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读的地方,它是与具有构造函数/析构非简单的全局本地对象。有人可以解释它究竟是什么,可能会造成麻烦?

I have read somewhere that it has something to do with non-simple global native objects that have constructors/destructors. Can someone explain what it is exactly that may cause trouble?

推荐答案

一个例子:有一次,我试图链接本地C ++ lib目录为C ++ / CLI应用程序。这lib中包含一个常量静态的std ::字符串。该应用程序也总是崩溃。原因:

An Example: Once I tried to link a native C++ lib into a C++/CLI application. That lib contained a const static std::string. The application did always crash. Reason:

在应用程序启动时,它初始化常量静态对象。为了确保静态对象获得的应用程序退出正确删除,编译器生成调用标准库函数的 atexit对。该调用导致了原生的C运行时,这是没有正确地在这个时间点上初始化的崩溃。

When the application starts, it initializes the const static objects. To make sure that the static objects get deleted properly on application exit, the compiler generates a call to the standard library function atexit. This call causes a crash in the native C runtime, which is not yet properly initialized at this point in time.

有一个与非const静态字段,这是初始化以后就没问题了。

There is no problem with non-const static fields, which are initialized later.

我认为这是一个错误 - 也许它是固定在此期间(我与Visual Studio 2005中的问题)。不幸的是,我不能提供一个适当的链接,但我希望这可以帮助你进一步的研究。

I consider this as a bug - maybe it is fixed in the meantime (I had the problem with Visual Studio 2005). Unfortunately, I cannot provide an appropriate link, but I hope this helps for your further research.

这篇关于为什么全球本地对象引起C ++ / CLI中的DLL问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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