[Qt-interest] Undefined symbol error when using singleton class with Qt plugins
Andreas Unger
andi.unger05 at gmail.com
Fri Jan 14 20:09:10 CET 2011
Ah, got it. Thanks!
On Fri, Jan 14, 2011 at 4:42 AM, <Oliver.Knoll at comit.ch> wrote:
> 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
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110114/a6da9508/attachment.html
More information about the Qt-interest-old
mailing list