QtPlugin and undefined symbol
FilePluginInterface.h
Code:
#ifndef FILEPLUGININTERFACE_H
#define FILEPLUGININTERFACE_H
#include "Geocache.h"
#include <QtPlugin>
#include <QIODevice>
#include <QString>
#include <QList>
class FilePluginInterface {
public:
virtual ~FilePluginInterface() {}
virtual const char *getName() const throw() = 0;
virtual const char *getVersion() const throw() = 0;
virtual const char *getAuthor() const throw() = 0;
virtual const char *getAuthorEmail() const throw() = 0;
virtual QList<Geocache
*> getAll
(QIODevice *source
) = 0;
};
Q_DECLARE_INTERFACE(FilePluginInterface, "com.Something.Plugins.FilePlugin/1")
#endif // FILEPLUGININTERFACE_H
GeocachingComGpx.cpp
Code:
#include "../../../src/FilePluginInterface.h"
class GeocachingComGpx
: public QObject,
public FilePluginInterface
{ Q_OBJECT
Q_INTERFACES(FilePluginInterface)
public:
const char *getName() const throw();
const char *getVersion() const throw();
const char *getAuthor() const throw();
const char *getAuthorEmail() const throw();
};
const char *GeocachingComGpx::getName() const throw()
{
return "Geocaching.com GPX Files";
}
const char *GeocachingComGpx::getVersion() const throw()
{
return "0.1.0";
}
const char *GeocachingComGpx::getAuthor() const throw()
{
return "James Marshall Hendrix";
}
const char *GeocachingComGpx::getAuthorEmail() const throw()
{
return "jimi@hendrix.com";
}
bool GeocachingComGpx
::isValid(QIODevice *source
) {
Q_UNUSED(source);
return true;
}
QList<Geocache
*> GeocachingComGpx
::getAll(QIODevice *source
){
Q_UNUSED(source);
return QList<Geocache*>();
}
Q_EXPORT_PLUGIN2(GeocachingComGpx, GeocachingComGpx);
GeocachingComGpx.pro
Code:
NAME = GeocachingComGpx
VERSION = 0.1.0
HEADERS += ../../../src/FilePluginInterface.h
SOURCES += GeocachingComGpx.cpp
TEMPLATE = lib
TARGET = $${NAME}
DESTDIR = ../../../bin/plugins/file/
DEPENDPATH += $$PWD
INCLUDEPATH += $$PWD
CONFIG += plugin
target.path = /usr/share/something/plugins/file/
INSTALLS += target
And when I'm trying to load a plugin:
Code:
for (QStringList::iterator it2
= files.
begin(); it2
!= files.
end(); it2
++) { QObject *plugin
= pluginLoader.
instance();
if (plugin) {
filePlugins.append(qobject_cast<FilePluginInterface*>(plugin));
qDebug() << "Loaded plugin" << filePlugins.last()->getName()
<< filePlugins.last()->getVersion();
} else {
qDebug() << pluginLoader.errorString();
}
}
pluginLoader.errorString() gives me
Code:
/some/nice/path/bin/plugins/file/libGeocachingComGpx.so: undefined symbol: _ZTV16GeocachingComGpx
_ZTV16GeocachingComGpx seems to be the symbol of my plugin's class (I looked into binary, methods symbols are prepended by it). Why it's missing from the binary? And if it's not, what's going on then?
Thanks for your time
Re: QtPlugin and undefined symbol
Ok, that was lame. I've just moved class declaration to a header file, and added it to HEADERS in .pro. Now everything works. Q_OBJECT macro just doesn't like source files.