Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking with a debug/release lib with qmake/Qt Creator

Tags:

c++

qt

qmake

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?

like image 766
Rob Avatar asked Jul 15 '09 08:07

Rob


People also ask

How do I create a dynamic library in Qt?

alternatively you can right-click your project in Qt Creator and select "Add Library...", choose "External library" and browse for your library file: For libraries compiled with MSCV compiler in windows, you look for . lib or . dll.

What is $$ PWD?

$$PWD means the dir where the current file (. pro or . pri) is. It means the same in LIBS .

Where is .pro file in Qt?

In the Qt Creator application, choose menu File->Open File or Project, navigate to the project folder and choose the . pro file to open.


2 Answers

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
    QMAKE_LIBDIR += "path/to/debug/lib"
} else {
    # release
    QMAKE_LIBDIR += "path/to/release/lib"
}

Cf. the qmake docs.

EDIT 2013-11-17: Don't use -Lfoo in LIBS. The canonical way is to add the paths (without the -L) to QMAKE_LIBDIR.

like image 152
Marc Mutz - mmutz Avatar answered Oct 22 '22 23:10

Marc Mutz - mmutz


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.

like image 43
Nick Avatar answered Oct 23 '22 00:10

Nick