什么预定义的宏可以用来检测调试构建与铛? [英] What predefined macro can be used to detect debug build with clang?

查看:118
本文介绍了什么预定义的宏可以用来检测调试构建与铛?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MSVC在调试模式下定义 _DEBUG ,gcc在发布模式下定义 NDEBUG

MSVC defines _DEBUG in debug mode, gcc defines NDEBUG in release mode. What macro can I use in clang to detect whether the code is being compiled for release or debug?

推荐答案

如果你看一下代码是否被编译为发布或调试, IDE的项目设置,你会看到那些宏实际上是手动定义的,它们不是由编译器自动定义的。事实上,编译器没有办法实际知道它是建立一个调试还是发布,它只是建立取决于用户(或IDE)提供给它的标志。

If you look at the project settings of your IDE, you will see that those macros are actually manually defined there, they are not automatically defined by the compiler. In fact, there is no way for the compiler to actually know if it's building a "debug" or "release", it just builds depending on the flags provided to it by the user (or IDE).

您必须自己创建宏并手动定义它们,就像IDE在创建项目时一样。

You have to make your own macros and define them manually, just like the IDE does for you when creating the projects.

这篇关于什么预定义的宏可以用来检测调试构建与铛?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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