0

I am trying to load a simple C based library interface that is contained of few functions, and compiled with qt as template lib. When I follow the standart way of loading the library, my QLibrary::load() fails. Here is the code:

    bool RecPluginMngr::loadLibrary(const QString &src)
{
    bool res = false;
    static QLibrary plugin(src);
    res = plugin.load();
    if (!res) {
        return res;
    }

    bool load_all_res = true;
    RecIface iface;
    iface.init = (init) plugin.resolve("init");
    // todo: err messages !!!

    if (iface.init == nullptr) {
        load_all_res &= false;
    }

    iface.get_data = (get_data) plugin.resolve("get_data");
    if (iface.get_data == nullptr) {
        load_all_res &= false;
    }

    iface.put_data = (put_data) plugin.resolve("put_data");
    if (iface.put_data == nullptr) {
        load_all_res &= false;
    }

    iface.put_ndata = (put_ndata) plugin.resolve("put_ndata");
    if (iface.put_ndata == nullptr) {
        load_all_res &= false;
    }
    // map them all
    m_plugins[src] = iface;
    return load_all_res;
}
Ilian Zapryanov
  • 1,132
  • 2
  • 16
  • 28
  • 1
    What does [`QLibrary::errorString`](http://doc.qt.io/qt-5/qlibrary.html#errorString) return after the load fails? – G.M. Nov 11 '16 at 16:19
  • Thanks for the hint: it returns something strange: Cannot load library libplugin-test.so: (libplugin-test.so: cannot open shared object file: No such file or directory) but I am passing it when I debug I see the string is the same file: libplugin-test.so ? Maybe I am using it wrong? – Ilian Zapryanov Nov 11 '16 at 17:08
  • 1
    I'm assuming you're running on Linux? From the docs. `QLibrary::load` "searches in all the system-specific library locations (e.g. LD_LIBRARY_PATH on Unix), unless the file name has an absolute path". So the first thing to do might be to specify an absolute path to the shared object to see if that helps. If it does you need to fix up your LD_LIBRARY_PATH environment variable (or OS specific equivalent). – G.M. Nov 11 '16 at 17:57
  • Thank you so much. It's as you say: it needs the absolute path: BUT: qtcreator lied to me: as a program arguments in RUN I've passed the absolute file path and it failed, but in the exe directory from the shell program name and full path to .so worked. Thanks again! – Ilian Zapryanov Nov 11 '16 at 18:15

0 Answers0