Adding Libraries Globally to QtCreator



  • Hey, I noticed that in Qt Creator - specifically on windows, but the same is true on every platform I've used it on - The standard libraries, and the windows sdk, and the open standard platform libs (openGL for example) are all referenced in the Qt Creator's editor's auto-complete feature. Specifically if you type...

    #include <v...
    

    it will suggest vector, and other headers from those three groupings that begin with "v*". Additionally after typing for example:

    vector<int> v;
    v.
    

    It will suggest all the methods for "vector" after the period and you can select one from the list.

    However for any other libraries, you have to add the library just to that specific project, instead of for example just being able to reference it by typing...

    #include <curl.h> // for example
    

    and if you're using cl.exe on windows and a static library, then you can also do...

    #pragma comment(lib, "curl.lib")
    

    and as long as "curl.lib" is in the lib path for the compiler, it will find and automatically import into the binary the static library.

    Question: How can I make the headers for the library globally available to Qt so that it suggests the headers and suggests the types and symbols of that header in their proper contexts like it does for the STL, OpenGL, and the Windows SDK as well as pass those headers to the compiler so that the compiler knows where they are?



  • It is based on your Environment Variables INCLUDEPATH and LIB.

    All you need to do is to add the libraries include path (i.e. where its .h files are) and the libraries path (where the .lib (for MSVC) or .a (for minGW) files are) to these two variables and restart the QT Creator.


  • Qt Champions 2016

    @GinoMan2440 said:

    However for any other libraries, you have to add the library just to that specific project, instead of for example just being able to reference it by typing...

    Your libraries (or more correctly headers) are not in system-wide recognized location.

    Question: How can I make the headers for the library globally available to Qt so that it suggests the headers and suggests the types and symbols of that header in their proper contexts like it does for the STL, OpenGL, and the Windows SDK as well as pass those headers to the compiler so that the compiler knows where they are?

    You can create a feature for qmake, where you add the paths to the headers and the binaries. You can use my repo where I've susbstituted the compilers as a template. The .prf file you copy in $QTDIR/mkspecs/features and you can use it with the CONFIG variable in your project, like this:

    CONFIG += my_cool_curl_feature
    

    Kind regards.


Log in to reply
 

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