debug 使用 release 的可执行程序

40 篇文章 0 订阅

You can certainly pass STL objects across DLL boundaries but all involved dlls/exes must be compiled using the same compiler and the same compilation options.

Remember that most of the STL code is inline. This means that every dll will get its own version of the code and that code assumes a particular binary layout of the STL objects. If you compile 2 dlls with different compilation options then it is possible that the binary layout is different so the assumption breaks.

In addition to this, if one dll is debug and one dll is release it means they're using different CRT dlls, msvcrxx.dll and msvcrxxD.dll. That itself is a problem, at a minimum this means that each dll will use a different memory allocator and pointers allocated in one dll can't be freed in another.

Your best bet is to not share things like STL objects and other things which allocate memory across DLL boundaries.  Things like HAS_ITERATOR_DEBUGGING and SECURE_SCL will cause you grief, but other more subtle things can cause huge headaches as well.

For one thing, there is a good chance that you have multiple copies of the C runtime each with a different heap, so allocating in one heap and freeing to another will cause corruption.

Once you have gone to the effort of making all thing things match that will need to match to make it possible to share stuff like STL objects you might as well have just started using static libraries in many cases.

the only supported DLL boundary that STL object can be shared between is your DLL and C++ runtime DLL. Doing otherwise will cause a lot of pain at some point. Do not do it.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值