QT Plugin loading problem
-
I'm trying to create an application that uses plugins, based on How to Create Qt Plugins and Echo Plugin Example. My project compiles, but the application fails to load the plugin at runtime i.e. QPluginLoader load() returns false. I've stripped what I've been doing down to a very minimal project that is similar to the actual one and still exhibits the problem and uploaded it here. I'm using Qt 6.1 (from source) and cmake on a Linux platform. Am I doing something incorrectly / what do I need to do to fix this?
-
Alright, for anyone who may be interested, I found the source of the problem!!
What I had before, in the Interface, was this
... virtual ~FooInterface(); ...
I've changed that to this:
... virtual ~FooInterface() {} ...
and now it works. It's those little details that get me sometimes...
-
I'm still trying to get to the bottom of this problem, but I've discovered something useful while following Deploying Plugins:Debugging Plugins.
Cannot load library /tmp/foo/lib/plugins/libfooplugin.so.0.1.0: (/tmp/foo/lib/plugins/libfooplugin.so.0.1.0: undefined symbol: _ZTI12FooInterface) QLibraryPrivate::loadPlugin failed on "/tmp/foo/lib/plugins/libfooplugin.so.0.1.0" : "Cannot load library /tmp/foo/lib/plugins/libfooplugin.so.0.1.0: (/tmp/foo/lib/plugins/libfooplugin.so.0.1.0: undefined symbol: _ZTI12FooInterface)"
Also of note, references to that symbol in libfooplugin.so (nm libfooplugin.so)
0000000000004640 W _ZN12FooInterfaceC1Ev 0000000000004640 W _ZN12FooInterfaceC2Ev U _ZN12FooInterfaceD2Ev U _ZTI12FooInterface U _ZTV12FooInterface
So it seems that when the plugin is loaded that it fails to recognize the interface, even though both the application project and plugin project are linked against the interface project and have access to the relevant header. If I had to hazard a guess, it may have something to do with the relevant symbol being an abstract class that is only defined in a header file, but I'm not sure how to fix this.
-
I'm still trying to get to the bottom of this problem, but I've discovered something useful while following Deploying Plugins:Debugging Plugins.
Cannot load library /tmp/foo/lib/plugins/libfooplugin.so.0.1.0: (/tmp/foo/lib/plugins/libfooplugin.so.0.1.0: undefined symbol: _ZTI12FooInterface) QLibraryPrivate::loadPlugin failed on "/tmp/foo/lib/plugins/libfooplugin.so.0.1.0" : "Cannot load library /tmp/foo/lib/plugins/libfooplugin.so.0.1.0: (/tmp/foo/lib/plugins/libfooplugin.so.0.1.0: undefined symbol: _ZTI12FooInterface)"
Also of note, references to that symbol in libfooplugin.so (nm libfooplugin.so)
0000000000004640 W _ZN12FooInterfaceC1Ev 0000000000004640 W _ZN12FooInterfaceC2Ev U _ZN12FooInterfaceD2Ev U _ZTI12FooInterface U _ZTV12FooInterface
So it seems that when the plugin is loaded that it fails to recognize the interface, even though both the application project and plugin project are linked against the interface project and have access to the relevant header. If I had to hazard a guess, it may have something to do with the relevant symbol being an abstract class that is only defined in a header file, but I'm not sure how to fix this.
Also of interest, if I inspect the objects with ldd, something is strange; even though I specified that the plugin and app should both link against the library, I don't see libfoocore.so in the output, so presumably it didn't actually link?
-
Alright, for anyone who may be interested, I found the source of the problem!!
What I had before, in the Interface, was this
... virtual ~FooInterface(); ...
I've changed that to this:
... virtual ~FooInterface() {} ...
and now it works. It's those little details that get me sometimes...