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