Pro file configuration for using a static lib



  • Hello,

    I have two projects, one is a lib file I included staticly in my other project.
    I want to do different things depending on OS, but too on Compiler.

    Here is the current code for the .a lib :
    @
    win32:CONFIG(release, debug|release): LIBS += -L../../QtWebsocket/release/ -lQtWebsocket
    else:win32:CONFIG(debug, debug|release): LIBS += -L../../QtWebsocket/debug/ -lQtWebsocket
    else:unix:!symbian: LIBS += -L../../QtWebsocket/ -lQtWebsocket

    win32:CONFIG(release, debug|release): PRE_TARGETDEPS += ../../QtWebsocket/release/libQtWebsocket.a
    else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += ../../QtWebsocket/debug/libQtWebsocket.a
    else:unix:!symbian: PRE_TARGETDEPS += ../../QtWebsocket/libQtWebsocket.lib
    @

    And here the code for the .lib file :
    @
    win32:CONFIG(release, debug|release): LIBS += -L../../QtWebsocket/release/ -lQtWebsocket
    else:win32:CONFIG(debug, debug|release): LIBS += -L../../QtWebsocket/debug/ -lQtWebsocket
    else:unix:!symbian: LIBS += -L../../QtWebsocket/ -lQtWebsocket

    win32:CONFIG(release, debug|release): PRE_TARGETDEPS += ../../QtWebsocket/release/QtWebsocket.lib
    else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += ../../QtWebsocket/debug/QtWebsocket.lib
    else:unix:!symbian: PRE_TARGETDEPS += ../../QtWebsocket/libQtWebsocket.lib
    @

    I wanted to know how I can improve my pro file to make it working in any configuration ?


  • Moderators

    @
    CONFIG+=staticlib
    @

    is enough in most situations.


  • Lifetime Qt Champion

    Maybe something like:
    @EXTENSION =
    LIBPATH =
    win32 {
    EXTENSION = lib
    CONFIG(release, debug|release) {
    LIBPATH = release
    } else {
    LIBPATH = debug
    }
    } else:unix:!symbian:EXTENSION=a

    LIBS += -L../../QtWebsocket/$$LIBPATH -lQtWebsocket
    PRE_TARGETDEPS += ../../QtWebsocket/$$LIBPATH/libQtWebsocket.$$EXTENSION
    @



  • OK, but in windows, the extension depends of the compilater. With QtCreator, I obtain a .a file, and with visual studio, I obtain a .lib file. You can I do that ?


  • Moderators

    So you are compiling with 2 different compilers. Their linkers should understand the extensions and add them automatically (after -lyourLibName call). Libs will not be binary compatible anyway.


  • Lifetime Qt Champion

    QtCreator will use the compiler that goes with the Qt you have selected, either mingw or msvc, it's up to you to choose which one to use.

    You have also more precise scopes if you need (IIRC win32-msvc for example)



  • ok, thanks, that's what I searched :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.