0

I am using QPluginLoader to build a QT application, using the Qt Plugin framework.

I have built a plugin, but the framework is failing to load the plugin. My plugin has a dependency on a third party shlib (log4qt).

The file is correctly identified, but loading the file fails (this immediately made me suspect a missing dependency).

I run ldd on the shlib, and in the output, this is the only missing file:

liblog4qt.so.1 => not found

I have tried the following to resolve the problem:

  1. Using QApplication::addtLibraryPath("Path to liblog4qt.*)
  2. Edited /etc/ld.conf to manually add library location and refreshed cache
  3. Copied all of the liblog4qt* files into my plugin directory

All of the above were as much use as a chocolate fireguard.

Here is how I am loading the plugin. Nothing unsual here ...

// Private methods
void MyApp::loadPlugins()
{
    //QString path = QApplication::applicationDirPath();

    QDir plugins_dir(".");

#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
    QString pdirname = plugins_dir.dirName().toLower();

    #if defined(Q_OS_WIN)
    if (dirname == "debug") || (dirname="release")
        plugins_dir.cdUp();

    #elif defined(Q_OS_MAC)
    if (dirname == "macos")
    {
        plugins_dir.cdUp();
        plugins_dir.cdUp();
        plugins_dir.cdUp();
    }
    #endif
#endif

    plugins_dir.cd("bin/plugins");

    foreach(QString filename, plugins_dir.entryList(QDir::Files))
    {
        qDebug() << "Filename: " << filename;

        if (!filename.toLower().contains("plugin"))
            continue;

        qDebug() << "Attempting to load: " << plugins_dir.absoluteFilePath(filename);

        QPluginLoader plugin_loader(plugins_dir.absoluteFilePath(filename));

        QString problem = plugin_loader.errorString();
        qDebug() <<  "Plugin load problem: " << problem;

        QObject * plugin = plugin_loader.instance();

        if (plugin)
        {
            PluginInterface * iplugin = qobject_cast<PluginInterface *>(plugin);

            if (iplugin) {
                /* do something useful */
            }
        }
    }
}

Here is the (relevant part of the) console output:

14-09-27 15:50:42.SSS [DEBUG] Qt: - Attempting to load:  "/path/to//main/bin/plugins/libplugin001.so" 
14-09-27 15:51:33.SSS [DEBUG] Qt: - Plugin load problem:  "Unknown error" 
14-09-27 15:51:53.SSS [DEBUG] Qt: - Attempting to load:  "/path/to//main/bin/plugins/libplugin001.so.1" 
14-09-27 15:51:53.SSS [DEBUG] Qt: - Plugin load problem:  "Unknown error" 
14-09-27 15:51:55.SSS [DEBUG] Qt: - Attempting to load:  "/path/to//main/bin/plugins/libplugin001.so.1.0" 
14-09-27 15:51:55.SSS [DEBUG] Qt: - Plugin load problem:  "Unknown error" 
14-09-27 15:51:57.SSS [DEBUG] Qt: - Attempting to load:  "/path/to//main/bin/plugins/libplugin001.so.1.0.0" 
14-09-27 15:51:57.SSS [DEBUG] Qt: - Plugin load problem:  "Unknown error" 

Does anyone know why my plugin library is NOT being loaded?

[[Additional Information]]

  • OS: Ubuntu 12.0.4 LTS
  • gcc: 4.6.3
  • QT: 4.8.1
  • QT Creator: 2.4.1
Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
  • Did you try to link your app against that missing library and build it? This will make sure that the linker can actually find that lib. – hank Sep 27 '14 at 19:58
  • Actually yes, the main app links against log4j and uses it successfully in the code. That's interesting - coming to think of it – Homunculus Reticulli Sep 27 '14 at 20:50
  • You're checking the error message before you actually load the plugin, that's why the message tells you nothing. The `plugin_loader.instance()` method does the loading (or you can call `load()` manually), so you should check any errors after that, not before. – Googie Oct 03 '14 at 09:45
  • Could you also post your .pro file? – Oleg Shparber Oct 04 '14 at 06:25
  • I had see somewhere in Qt documentation, that pluigns should be designed without dependencies to other qt plugins. To override this issue, I implemented my own plugin system (sadly). – Dmitry Sazonov Oct 04 '14 at 19:22

0 Answers0