Results 1 to 3 of 3

Thread: QPluginLoader: loading plugin library with another shared lib dependency (linux)

  1. #1
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question QPluginLoader: loading plugin library with another shared lib dependency (linux)

    Hi All,

    hope you can help me with a "convenience" issue. I'm writing an application with plugin-support on Linux. As these plugins shall be updated outside the general "apt-get update & upgrade" mechanism (with user priviliges) there are located in some subdirectory of the home path. The plugins are configured to be used with QPluginLoader. The plugin-libraries depend on other shared libraries themselves, which are also located in some local path or in the same path as the plugin library.

    Normally, the locations of the plugins are NOT listed in LD_LIBRARY_PATH (as this is a system-wide variable and should normally not be adjusted when installing/uninstalling plugins).

    I have created a minimalistic test setup in https://github.com/ghorwin/CppCodingTutorials, subdirectory Qt/plugins
    (clone the repo, load the three projects in the directory, build and test yourself).


    This is the setup:
    - PluginLoader loads the plugin library “TestPlugin” at runtime
    - TestPlugin requires TestLib as shared library dependency

    When running the test, the plugin-loader complains with the errorString:

    "Cannot load library /home/ghorwin/git/CppCodingTutorials/Qt/plugins/lib/libTestPlugin.so.1.0.0: (libTestLib.so.1: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden)"

    However, when I add the local path to the so-files to LD_LIBRARY_PATH, linking works fine (you can try this in QtCreator easily yourself, by adjusting LD_LIBRARY_PATH in the execution environment).


    As recommended by the Qt documentation, I added the library search path to QCoreApplication as follows:

    Qt Code:
    1. qApp->addLibraryPath(pluginDir.absolutePath()); // BUG: THIS DOES NOT WORK
    2. qDebug() << qApp->libraryPaths(); // Shows our so directory
    3. bool success = pd.m_loader->load(); // load the plugin - failes to load plugin, as dependency libTestLib.so is not found
    To copy to clipboard, switch view to plain text mode 

    Adding a library search path via addLibraryPath apparently does not work.


    Here are my questions:

    - Would you have any idea why addLibraryPath() does not work as expected on Linux?
    - Ist there any alternative to adjusting the LD_LIBRARY_PATH environment variable prior to loading the plugins?


    Thanks for any ideas!

    -Andreas
    Andreas

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    513
    Thanks
    12
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader: loading plugin library with another shared lib dependency (linux)

    Hi, my guess my addLibraryPath() does not work as you expect is that the dependencies of your plugin are not handled by your Qt program (where you called addLibraryPath), but by the "normal" procedure, which relies on LD_LIBRARY_PATH and does not know about the addLibraryPath() call.

    One alternative could be that you use static linking to link libTestLib.so.1 (or the corresponding .a file) to your plugin.

    Ginsengelf

  3. #3
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPluginLoader: loading plugin library with another shared lib dependency (linux)

    Quote Originally Posted by Ginsengelf View Post
    Hi, my guess my addLibraryPath() does not work as you expect is that the dependencies of your plugin are not handled by your Qt program (where you called addLibraryPath), but by the "normal" procedure, which relies on LD_LIBRARY_PATH and does not know about the addLibraryPath() call.

    One alternative could be that you use static linking to link libTestLib.so.1 (or the corresponding .a file) to your plugin.
    As for your "guess", this matches my observation. My expectation was, however, that when loading the shared library the Qt code somehow updates the LD_LIBRARY_PATH variable locally, then loads the library (with the typical linux-style dlopen() call and restores the environment variable afterwards. However, this won't work, as the man page for dlopen() clearly states:

    • If, at the time that the program was started, the environment
    variable LD_LIBRARY_PATH was defined to contain a colon-
    separated list of directories, then these are searched. (As a
    security measure, this variable is ignored for set-user-ID and
    set-group-ID programs.)
    So, as there is no other way to tell dlopen() where to search for (indirectly linked) shared libs, my setup won't work on Linux.

    As for the suggestion to link all dependent libraries statically, this is - unfortunately- not possible in all cases due to licensing restrictions.

    The only remaining option I see here is to somehow edit the DT_RUNPATH ELF variable in my library, as this seems to be the only remaining way to tell ldopen() where to search for libraries.
    Anyway, this is not a Qt issue (anylonger), hence I'm closing the topic.
    Andreas

Similar Threads

  1. Problem with dependency on shared library and internal class
    By remizero in forum Installation and Deployment
    Replies: 6
    Last Post: 4th March 2017, 13:17
  2. Using symbols from loading application in shared library
    By barteksch in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2010, 17:08
  3. Application with shared library problem in linux
    By cutie.monkey in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2010, 07:20
  4. Qmake fails to set shared library dependency
    By jkv in forum Qt Programming
    Replies: 5
    Last Post: 3rd September 2009, 13:44
  5. qmake: dependency of application on common shared library
    By PeterWurmsdobler in forum Qt Programming
    Replies: 5
    Last Post: 27th March 2009, 16:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.