且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

混合STL调试/发布库

更新时间:2023-11-14 19:26:40

这是未定义的行为,因此它可能会起作用,但更有可能会使您的应用程序崩溃.它还取决于stl的实现,在调试版本中,它可能启用附加检查并分配附加内存,从而使数据布局在发布模式下有所不同.最后,这违反了ODR规则(一种定义规则),再次导致未定义的行为.

This is undefined behaviour, so it might work but more probably it will crash your app. It also depends on stl implementation, in debug version it might enable additional checks and allocate additional memory making data layout different in release modes. In the end this violates ODR rule (one definition rule) once again causing undefined behaviour.

我有一个QT项目,它以发行版"的形式建立,但它在编译器标志中添加了/DEBUG.如果我在"debug"(也带有/DEBUG标志)下构建另一个QT项目,它们兼容吗?

I have a QT project that gets built as 'release', but it has /DEBUG added to the compiler flags. If I build another QT project under 'debug' (which also has the /DEBUG flag), are they compatible?

如果您的Release包含与Debug完全相同的编译器标志,那么我会说它们是兼容的.

If your Release contains exactly the same compiler flags as Debug then I would say they are compatible.

或者是否存在优化标记或其他使它们不兼容的标记?

Or is there an optimization flag or some other flag that makes them incompatible?

您应该能够看到这些标志,我不认为优化标志会导致UB问题,因为在编译阶段使用的宏标志与ODR违背的宏非常不同.也许有优化标志会改变结构的对齐方式.

you should be able to see those flags, I dont think optimization flags should cause UB problems, its rather different macros used during compilation phase that cause ODR violation. Maybe there are optimization flags which changes alignment in structures...

基本上,有没有办法让我看一下2个库的编译行,并看到显示请勿混合!"的内容?

Basically, is there a way I can look at the compilation line of the 2 libraries and see something that says "DON'T MIX THESE!"?

在这里不知道.

为什么首先要混合使用不同的构建库?这是自找麻烦.

Why are you mixing differently build libraries in the first place? this is asking for trouble.