tags:

views:

2317

answers:

2

I am using Qt Creator and have a Qt GUI project that depends on a C++ static library project. I want to link the release version of the GUI app with the release build of the .lib and the debug release of the GUI app with the debug .lib. I have found out how to add additional libraries to the project by including a line like the following in my .pro file:

LIBS += -L./libfolder -lmylib.lib

But I cannot see how I can use a different -L command for release and debug builds.

Is there support in qmake to do this?

+5  A: 

In your project file you can do something like this

debug {
    LIBS += -L./libfolder -lmydebuglib.lib
}

release {
    LIBS += -L./libfolder -lmyreleaselib.lib
}

The bit inside the debug braces is used if DEBUG has been added to the CONFIG qmake variable, similarly stuff inside the release brackets is included if RELEASE has been added to the CONFIG variable.

You can also use "!debug" rather than "release" (i.e. when debug isn't in the config)

You can find more information on qmake here.

Nick
+9  A: 

The normal

debug:LIBS += ...
else:LIBS += ...

solution breaks when users naively use CONFIG += debug or CONFIG += release to switch between debug and release builds (and they do; no-one remembers to say CONFIG -= release release_and_debug before CONFIG += debug :).

This is the canonical way to scope on debug:

CONFIG( debug, debug|release ) {
    # debug
} else {
    # release
}

Cf. the qmake docs