Shared library dependencies in plugins



  • This is not so much of a question but rather a request for clarification. My typical subdirs project in Qt Creator looks something like this:

    app
    libCommon
    libOther
    pluginA
    pluginB
    pluginC
    ...
    

    Basically what this does is the following:

    1. All plugin interfaces AND common classes/features required throughout the project are all in libCommon. Similarly the other libraries group classes that are required by more than one plugin. These shared libraries are depended on by other sub-projects using this code in their project file:

       win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../libs/libAACommon/release/ -llibAACommon
       else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../libs/libAACommon/debug/ -llibAACommon
       else:unix: LIBS += -L$$OUT_PWD/../../libs/libAACommon/ -llibAACommon
      
       INCLUDEPATH += $$PWD/../../libs/libAACommon
       DEPENDPATH += $$PWD/../../libs/libAACommon
      
    2. pluginA etc. are sub-projects that provide features and functionality to the program and are loaded dynamically on runtime using QPluginLoader starting with core/gui plugin(s) in the app.

    Now I have found out that if a plugin depends on a library (e.g. pluginA depends on libOther) then I HAVE to use the code above to include that library in the project file of the app or else the plugin will fail to load. So basically the app sub-project MUST include every library in the project even if it does not directly depend on it (but plugins it will directly or indirectly load do depend on it).

    This is confusing to me and I would like to know why is that and if it could be done so that the dependencies of the plugin are only loaded with it (when it is loaded) rather than being all pre-loaded with the application start.

    I do actually know of the solution and that is using QLibrary to manually load the libraries. Is there any other?


  • Lifetime Qt Champion

    Hi,

    You need to have your DLL's in a path where the plugins can find them. This usually means either having them in the same folder as the application or modify the PATH environment variable in the Run panel of your project so that these DLL's can be found. On Windows you would usually have the DLL's put in the same folder as the application.

    Hope it helps



  • It seems right but unfortunately I cannot test if it is working. Whenever I remove the libraries from the main executable I cannot even compile it because it complains about the missing dependencies, e.g.

    class AAApplication : public ACGuiApplication
    

    where AAApplication is part of libCommon (internal shared library) and ACGuiApplication is part of another external shared library properly included as dependency of libCommon that builds just fine.

    But when I try to use the AAApplication in app and only include libCommon as its dependency (because it is) it fails to compile because it cannot find ACGuiApplication. Therefore I have to include all dependencies of everything in the project in the app as well or else it won't even compile (even if it could run the plugins if everything was in one place).


  • Lifetime Qt Champion

    ACGuiApplication is a symbol that comes from that other library so it's not provided by libCommon. Have a look at the link_prl and create_prl qmake options. They should provide you with all the dependencies needed automatically.



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