Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

What do INCLUDEPATH and LIBS do?



  • Hi,

    I would like to know, how can I use this words in my .pro file.

    When I would like to add to my project other headers I can use INCLUDEPATH. For example I would like to add myheader.h, which is located in:
    C:\Users\John\abc\def\myheader.h

    Which variant I have to select?
    INCLUDEPATH += "C:\Users\John\abc\def"
    or
    INCLUDEPATH += "C:\Users\John\abc"

    And next: for example I have file myLibFile.lib, which has functions from myheader.h and this file is located here:
    C:\Users\John\xyz\hij\myLibFile.lib

    I think I can add this library to my project using:

    LIBS += -LC:\Users\John\xyz\hij -lmyLibFile

    But can I do something like that:
    LIBS += -LC:\Users\John\xyz -lmyLibFile ?

    What when I do:
    LIBS += -LC:\Users\John\xyz\hij -LC:\path\to\other\folder -lmyLibFile ?

    Is the correct way in LIBS like this:
    LIBS += -LpathToFolderWithLibs -lnameOflib1 -lnameOfLib2 -LpathToFolder2WithLibs -lname2Oflib1 -lname2OfLib2 -lname2OfLib3 ?

    So first I add nameOflib1.lib and nameOfLib2.lib, which are located in pathToFolderWithLibs, and next I add name2Oflib1.lib, name2OfLib2.lib, name2OfLib3.lib, which are located in pathToFolder2WithLibs.

    I have to always add LpathToFolderWithLibs in LIBS before add libraries ( like -lnameOflib1 )?


  • Lifetime Qt Champion

    @qwe3 Is explained in documentation:
    https://doc.qt.io/qt-5/qmake-variable-reference.html#includepath
    https://doc.qt.io/qt-5/qmake-variable-reference.html#libs

    "Which variant I have to select?" - depends on how you include the header file. If you do it like "#include "myheader.h"" then INCLUDEPATH += "C:\Users\John\abc\def" is correct.

    "But can I do something like that:
    LIBS += -LC:\Users\John\xyz -lmyLibFile ?" - weel, how should that work if the lib is inside hij subfolder?

    "What when I do:
    LIBS += -LC:\Users\John\xyz\hij -LC:\path\to\other\folder -lmyLibFile ?" - why would you do that?

    "I have to always add LpathToFolderWithLibs in LIBS before add libraries" - only if the libraries are located in folders which are not searched by default. For example on Linux you do not need -Lpath for libraries located in /usr/lib*.


  • Lifetime Qt Champion

    @qwe3 Is explained in documentation:
    https://doc.qt.io/qt-5/qmake-variable-reference.html#includepath
    https://doc.qt.io/qt-5/qmake-variable-reference.html#libs

    "Which variant I have to select?" - depends on how you include the header file. If you do it like "#include "myheader.h"" then INCLUDEPATH += "C:\Users\John\abc\def" is correct.

    "But can I do something like that:
    LIBS += -LC:\Users\John\xyz -lmyLibFile ?" - weel, how should that work if the lib is inside hij subfolder?

    "What when I do:
    LIBS += -LC:\Users\John\xyz\hij -LC:\path\to\other\folder -lmyLibFile ?" - why would you do that?

    "I have to always add LpathToFolderWithLibs in LIBS before add libraries" - only if the libraries are located in folders which are not searched by default. For example on Linux you do not need -Lpath for libraries located in /usr/lib*.



  • @jsulm thank you

    What win32 means? For example: win32:LIBS += -liphlpapi. Can I no add win32 word like this: LIBS += -liphlpapi?


  • Lifetime Qt Champion

    @qwe3 said in What do INCLUDEPATH and LIBS do?:

    win32

    This is scope for Windows, see https://doc.qt.io/qt-5/qmake-language.html#scopes
    "Can I no add win32 word like this: LIBS += -liphlpapi?" - the point is that you often need to include different libs for different platforms, that is what scopes are used for.



  • @jsulm So that word ( win32 ) is only to add some thing ( like library ) only when I compile application on windows?


  • Lifetime Qt Champion

    @qwe3 Yes


Log in to reply