天天看点

qmake 之 CONFIG(debug, debug|release)

http://hi.baidu.com/dbzhang800/item/759aa224fc1140c9a4275a41

qmake 之 CONFIG(debug, debug|release)

问题

在 Qt 编程中,多数人用的都是 qmake,并编写相应pro文件。

实际中经常需要对 debug 与 release 两种编译模式 设置不同的选项,比方说链接不同库

遇到该问题,简单看看qmake的manual,不少人都会写出类似下面的内容:

debug {

LIBS += -L../lib1 -lhellod

}

release {

LIBS += -L../lib2 -lhello

很不幸,这么做通常不能正常工作。

如果打开看生成的makefile文件,会发现 无论是debug还是release,上面的两个语句都会同时起作用。也就是说,上面相当于

LIBS += -L../lib1 -lhellod -L../lib2 -lhello原因

这是很违反直觉的,因为CONFIG可以同时定义 debug 和 release,但只有一个处于active(当两个互斥的值出现时,最后设置的处于active状态)

比如:

CONFIG = debug

CONFIG += release

...

这种情况下,release处于active状态,但,debug 和 release 都能通过上面的测试。

如何解决

CONFIG(debug, debug|release) {

} else {

CONFIG(debug, debug|release):LIBS += -L../lib1 -lhellod

CONFIG(release, debug|release):LIBS += -L../lib2 -lhello

那么,CONFIG(debug, debug|release) 这种语法是什么含义呢?

两个参数,前者是要判断的active的选项,后者是互斥的选项的一个集合。

参考

  • http://doc.trolltech.com/latest/qmake-function-reference.html#config-config
  • http://developer.qt.nokia.com/faq/answer/what_does_the_syntax_configdebugdebugrelease_mean_what_does_the_1st_argumen
  • http://www.qtcentre.org/threads/28049-qmake-Project-file-has-both-quot-debug-quot-and-quot-release-quot-conditions-true
  • http://stackoverflow.com/questions/1130106/linking-with-a-debug-release-lib-with-qmake-qt-creator
  1. build_pass:CONFIG(debug, debug|release){
  2. message(Debug bulid)
  3. else:build_pass {
  4. message(Release build)

To build from command line, just call:

Debug build:

  1. qmake
  2. make debug
  1. make release
Qt

继续阅读