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

后端 未结 2 1711
無奈伤痛
無奈伤痛 2020-12-08 07:27

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 th

相关标签:
2条回答
  • 2020-12-08 08:03

    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.

    0 讨论(0)
  • 2020-12-08 08:03

    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.

    0 讨论(0)
提交回复
热议问题