[Qt-interest] Undefined symbol error when using singleton class with Qt plugins

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Fri Jan 14 10:42:17 CET 2011


On 2011-01-14 Andreas Andreas Unger wrote:

> ...
> Could someone please help me figure out why I get this error when I 
> try to run the code:
> 
> ./Test: symbol lookup error: libtestplugin.so: undefined symbol:
> _ZN9Singleton8instanceEv

When linking your plugin it does not find the method Singleton::instance() which you call here

void TestPlugin::printTestString()
{
    qDebug() << Singleton::instance()->testString();
}

(You figured /that/ out probably yourself ;)

The reason is this method is implemented in the actual executable. Let alone that you did not specify any additional libraries to link with in your TestPlugin.pro it is not possible for any library/executable to link against an executable! You have to link against libraries (aka "DLLs", "shared objects", "dynamic libraries", ...). And yes, when you compile your libraries (and in the end a plugin is just that) you must also make sure that ALL references are satisfied at link time (1)!

So what you want is the following:

Your application, consisting of
- *.exe (which links against the application DLLs)
- *.dll(s) (which contain(s) the actual program logic, and which the plugins can use)

Your plugins
- YourPlugin.dll (which links against the application DLLs)
- *.dll(s) (the application DLLs) 

(1) However it /might/ be possible with certain compiler switches to leave these references unresolved at compile time, and only try to resolve them at runtime. I think that was your understanding of how plugins work. I am not aware of these switches and think that is not so good anyway, since you detect errors ("unsatisfied symbols") very late in the development process, only when you actually try to run the application/plugin, wheras in the "normal approach" you already detect these errors at link time - just as you experienced ;)

Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22





More information about the Qt-interest-old mailing list