混合STL调试/发布库 [英] Mixing STL debug/release libraries

查看:49
本文介绍了混合STL调试/发布库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,混合使用将STL容器相互传递的调试和发行库会引起很大的问题.但是到底是什么导致调试"或发布"呢?

I'm aware that mixing debug and release libraries that pass STL containers to each other causes big problems. But what exactly in 'debug' or 'release' causes this?

我有一个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?

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

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

基本上,有没有办法让我看一下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!"?

推荐答案

这是未定义的行为,因此它可能会起作用,但更有可能会使您的应用程序崩溃.它还取决于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.

这篇关于混合STL调试/发布库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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