Using a static library in Qt Creator

后端 未结 5 939
野趣味
野趣味 2020-12-04 12:35

I\'m having a hell of a time finding documentation which clearly explains how to use a static library in Qt Creator.

I\'ve created and compiled my static library usi

5条回答
  •  渐次进展
    2020-12-04 13:32

    In your project that uses the library make the LIBS variable point to your lib's path.
    To include files from the library, add the library folder to the INCLUDEPATH and then do a regular #include in your code files.

    e.g:

    # the binary's .pro  
    LIBS += c:/mylibs/math.lib
    INCLUDEPATH += c:/mylibs
    

    Edited:
    -L tells qmake that the path is a directory that it can search for libraries -l tells it that the path is a file, but take note of the observation below.

    From the qmake docs:

    This variable contains a list of libraries to be linked into the project. You can use the Unix -l (library) and -L (library path) flags and qmake will do the correct thing with these libraries on Windows (namely this means passing the full path of the library to the linker). The only limitation to this is the library must exist, for qmake to find which directory a -l lib lives in.

    Note: On Windows, specifying libraries with the -l option, as in the above example, will cause the library with the highest version number to be used; for example, libmath2.lib could potentially be used instead of libmathlib. To avoid this ambiguity, we recommend that you explicitly specify the library to be used by including the .lib file name suffix.

提交回复
热议问题