【问题标题】:RELEASE DEBUG in CMake [duplicate]在 CMake 中发布调试 [重复]
【发布时间】:2020-05-10 18:17:15
【问题描述】:

我试图为我的项目设置两种不同类型的代码。当我尝试运行以下代码时,没有打印任何内容。我正在使用 cmake 和 mingw。

#include <iostream>

int main(int, char**) {
#if DEBUG
std::cout<<"Hello from debug"<<std::endl;
#endif
#if RELEASE
std::cout<< "Hello from release"<<std::endl;
#endif
}

【问题讨论】:

  • 使用NDEBUG 所以#ifndef NDEBUG
  • 谢谢。这对我有用。

标签: c++ cmake


【解决方案1】:

我建议使用NDEBUG,因为它是标准化的。它是为非调试定义的——虽然通常与assert 一起使用,但我也将它用于其他用途。

#include <iostream>

int main() {
#ifndef NDEBUG
    std::cout << "Hello from debug" << std::endl;
#else
    std::cout << "Hello from release" << std::endl;
#endif
}

【讨论】:

    猜你喜欢
    • 2011-12-05
    • 2016-12-14
    • 2018-11-13
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多