Why do global native objects cause problems in C++/CLI dlls?
I have r开发者_开发技巧ead 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?
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:
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.
There is no problem with non-const static fields, which are initialized later.
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.
精彩评论