Search code examples
c++macosqtqt-creatordylib

How do you use a dynamic library with qt gui application?


I think I've created a .dylib file using this line in Terminal

g++ -dynamiclib -o myLib.dylib myLib.cpp

I've created QT widget application in a separate location.

I've tried to find a solution on SO and elsewhere, but I can't figure out how to get my application to use the dylib file.

Any help is much appreciated.


Solution

  • If you are using a .pro file, from the documentation, you can easily use the LIBS keyword and set properly the include paths.
    As an example (from the documentation):

    LIBS += -L/usr/local/lib -lmath
    INCLUDEPATH = c:/msdev/include d:/stl/include
    

    If you are using cmake, instead, you can use target_include_libraries and target_link_libraries to do almost the same.
    See here for further details about the available commands.

    If you are launching it from the command line, you can use -I and -L arguments to do that.
    See the documentation of your compiler for further details.

    And so on. How to do that mostly depends on the build process you decided to follow.