Qt Creator的CONFIG(debug,release)开关无效。

7

问题:在Linux上使用Qt Creator 2.8.1时,无论选择debug或release,CONFIG(debug, debug|release)和CONFIG(release, debug|release)总是被评估。

我的Qt Creator应用程序配置(股票 - 新项目的默认设置):

Projects->Build Settings->Debug Build Steps:
  qmake build configuration: Debug
  Effective qmake call: qmake2 proj.pro -r -spec linux-gnueabi-oe-g++ CONFIG+=debug

Projects->Build Settings->Release Build Steps:
  qmake build configuration: Release
  Effective qmake call: qmake2 proj.pro -r -spec linux-gnueabi-oe-g++

我的proj.pro配置如下:

message(Variable CONFIG:)
message($$CONFIG)
CONFIG(debug,debug|release)
{
    message(Debug build)
}
CONFIG(release,debug|release)
{
    message(Release build)
}

调试时在控制台输出:

Project MESSAGE: Variable CONFIG:
Project MESSAGE: lex yacc warn_on debug uic resources warn_on release incremental link_prl no_mocdepend release stl qt_no_framework debug console
Project MESSAGE: Debug build
Project MESSAGE: Release build

发布版本的控制台输出:

Project MESSAGE: Variable CONFIG:
Project MESSAGE: lex yacc warn_on uic resources warn_on release incremental link_prl no_mocdepend release stl qt_no_framework console
Project MESSAGE: Debug build
Project MESSAGE: Release build

在Windows 7下,我没有遇到任何与这样的.pro配置相关的问题,它可以正常工作。我感到绝望并修改了.pro文件。
CONFIG = test
message(Variable CONFIG:)
message($$CONFIG)
CONFIG(debug,debug|release)
{
    message(Debug build)
}
CONFIG(release,debug|release)
{
    message(Release build)
}

而我对输出结果感到惊讶:

Project MESSAGE: Variable CONFIG:
Project MESSAGE: test
Project MESSAGE: Debug build
Project MESSAGE: Release build

即使我完全清除CONFIG变量,它仍然会看到调试和发布配置。我做错了什么?

也许尝试运行“qmake CONFIG-=Debug”以进行发布,而运行“qmake CONFIG-=Release”以进行调试。 - dvvrd
正如您在第一段代码引用中所看到的,我正在这样做。 - killdaclick
不是的,我看到的是 CONFIG+=debug,而不是 CONFIG-=debug - dvvrd
抱歉,你是正确的 - 在发布之前我已经将项目恢复到默认设置,但一开始我测试了DEBUG: CONFIG- = release CONFIG+ = debug; RELEASE: CONFIG- = debug CONFIG+ = release。那是我在Windows项目中的默认配置,但在Linux Qt Creator下它没有起作用 - 这就是我为什么要写这篇文章的原因。此外,标准的Qt Creator不能像我描述的那样工作。 - killdaclick
1个回答

22

Qmake的设计可能有些疯狂,这可能是唯一合理的解释。整个发布/调试配置多次出现在 config 中,这就像一个旧的设计缺陷,从未在写入太多配置之前得到解决。还记得Makefile文件中的Tab吗?Dude(作者)只有15个用户,所以他从未纠正过错误的决策。

无论如何。

我在Linux上,Qt 4.8.4.1版本中看到了相同的问题。

这里是解决方案:在大括号之前删除换行符。

简而言之,这样做有效:

CONFIG(release, debug|release) {
    message(Release)
}

CONFIG(debug, debug|release) {
    message(Debug)
} 

虽然这个不做:

CONFIG(release, debug|release) 
{
    message(Release)
}

CONFIG(debug, debug|release) 
{
    message(Debug)
} 

我怀疑这是几个 qmake 版本中的解析错误,可能仅限于 Linux 系统。


1
仍然是一个问题在Windows上,Qt 5.3.1,Qt Creator 3.1.2。 - Bryan Greenway
将Qt 5.6添加到列表中...-______- - kayleeFrye_onDeck

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接