C++ -DNDEBUG 通常来自哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1878645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 21:28:27  来源:igfitidea点击:

Where does the -DNDEBUG normally come from?

c++makefilendebug

提问by WilliamKF

Our build system has somehow changed such that optimized builds are no longer getting the -DNDEBUG added to the compile line. I searched our makefiles and don't find this.

我们的构建系统发生了某种变化,优化后的构建不再将 -DNDEBUG 添加到编译行中。我搜索了我们的 makefile 并没有找到这个。

So the question is, where does -DNDEBUG originate for most people and how might that have changed? Before we did have -DNDEBUG and I don't think this was removed from any of our makefiles.

所以问题是,对于大多数人来说 -DNDEBUG 是从哪里开始的,它可能会发生怎样的变化?在我们确实有 -DNDEBUG 之前,我认为这不会从我们的任何 makefile 中删除。

Thanks.

谢谢。

-William

-威廉

采纳答案by Tal Pressman

Since the compiler can't decide on its own when to add the NDEBUG define and when not to, the flag is always set by either the makefile or project file (depending on your build system).

由于编译器无法自行决定何时添加 NDEBUG 定义以及何时不添加,因此该标志始终由 makefile 或项目文件设置(取决于您的构建系统)。

回答by William Pursell

It is really difficult to answer this since you didn't specify the build system you are using. If you're using autoconf, then either the user is expected to put -DNDEBUG in CPPFLAGS manually (or perhaps you were setting it from a CONFIG_SITE file that has changed), or the configure.ac might set up a custom variable for setting NDEBUG, or configure.ac may invoke AC_HEADER_ASSERT, in which case adding --disable-assert to the invocation of configure will define NDEBUG in config.h. There are lots of ways it can happen.

由于您没有指定正在使用的构建系统,因此很难回答这个问题。如果您使用的是 autoconf,那么用户应该手动将 -DNDEBUG 放入 CPPFLAGS(或者您可能是从已更改的 CONFIG_SITE 文件中设置它),或者 configure.ac 可能会设置一个自定义变量来设置 NDEBUG ,或者 configure.ac 可能会调用 AC_HEADER_ASSERT,在这种情况下,将 --disable-assert 添加到 configure 的调用将在 config.h 中定义 NDEBUG。它可以通过多种方式发生。

回答by Zach Hirsch

In my experience, -DNDEBUG has been passed manually, i.e. the makefiles have been written in such a way that the flag is passed when building in release mode.

根据我的经验,-DNDEBUG 是手动传递的,即生成文件的编写方式使得在发布模式下构建时传递标志。