This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Multiple definition errors when writing KRunner plugins

Tags: None
(comma "," separated)
Bakuriu
Registered Member
Posts
4
Karma
0
I'm trying to write a simple KRunner plugin but I have stumbled in an error that I'm unable to understand.

The header file that defines the runner plugin is the following (file name: unicodesymbolsrunner.h):

Code: Select all
#ifndef UNICODESYMBOLSRUNNER_H
#define UNICODESYMBOLSRUNNER_H

#include <KRunner/AbstractRunner>

class UnicodeSymbolsRunner : public Plasma::AbstractRunner
{
    Q_OBJECT

public:
    UnicodeSymbolsRunner(QObject *parent, const QVariantList &args);
    ~UnicodeSymbolsRunner();
    void match(Plasma::RunnerContext &);
    void run(const Plasma::RunnerContext &, const Plasma::QueryMatch &);
    void reloadConfiguration();
};

K_EXPORT_PLASMA_RUNNER(unicodesymbolsrunner, UnicodeSymbolsRunner)

#endif // UNICODESYMBOLSRUNNER_H


And the implementation is:
Code: Select all
#include "unicodesymbolsrunner.h"

UnicodeSymbolsRunner::UnicodeSymbolsRunner(QObject *parent, const QVariantList &arg) { }
UnicodeSymbolsRunner::~UnicodeSymbolsRunner() {}
void UnicodeSymbolsRunner::match(Plasma::RunnerContext &) {}
void UnicodeSymbolsRunner::run(const Plasma::RunnerContext &, const Plasma::QueryMatch &) {}
void UnicodeSymbolsRunner::reloadConfiguration() {}


As you can see it literally doesn't do anything.

When trying to compile this using QtCreator I get errors on the line containing the call to the K_EXPORT_PLASMA_RUNNER macro saying that I have multiple definitions of factory::factory() and stuff like that. Here's the error messages:


Code: Select all
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: multiple definition of `factory::factory()'
unicodesymbolsrunner.o:/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: first defined here
moc_unicodesymbolsrunner.o: In function `qt_noop()':
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: multiple definition of `factory::factory()'
unicodesymbolsrunner.o:/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: first defined here
moc_unicodesymbolsrunner.o: In function `factory::~factory()':
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: multiple definition of `factory::~factory()'
unicodesymbolsrunner.o:/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: first defined here
moc_unicodesymbolsrunner.o: In function `factory::~factory()':
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: multiple definition of `factory::~factory()'
unicodesymbolsrunner.o:/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: first defined here
moc_unicodesymbolsrunner.o: In function `factory::~factory()':
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: multiple definition of `factory::~factory()'
unicodesymbolsrunner.o:/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: first defined here
moc_unicodesymbolsrunner.o: In function `QObject* KPluginFactory::createInstance<UnicodeSymbolsRunner, QObject>(QWidget*, QObject*, QList<QVariant> const&)':
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: multiple definition of `kde_plugin_version'
unicodesymbolsrunner.o:/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: first defined here


How is this possible? Factory should be something handled by that macro. Does anyone know why this could happen?


Here's the whole output including the compiling commands that QtCreator is using:
Code: Select all
g++ -c -pipe -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SQL_LIB -DQT_CORE_LIB -I../UnicodeSymbolsRunner -I. -isystem /usr/include/KF5 -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtWidgets -isystem /usr/include/qt5/QtGui -isystem /usr/include/qt5/QtSql -isystem /usr/include/KF5/KRunner -isystem /usr/include/KF5/KService -isystem /usr/include/KF5/KConfigCore -isystem /usr/include/KF5/KCoreAddons -isystem /usr/include/qt5/QtCore -I. -I. -I/usr/lib/qt5/mkspecs/linux-g++ -o unicodesymbolsrunner.o ../UnicodeSymbolsRunner/unicodesymbolsrunner.cpp
../UnicodeSymbolsRunner/unicodesymbolsrunner.cpp:3:53: warning: unused parameter 'parent' [-Wunused-parameter]
 UnicodeSymbolsRunner::UnicodeSymbolsRunner(QObject *parent, const QVariantList &arg)
                                                     ^
../UnicodeSymbolsRunner/unicodesymbolsrunner.cpp:3:81: warning: unused parameter 'arg' [-Wunused-parameter]
 UnicodeSymbolsRunner::UnicodeSymbolsRunner(QObject *parent, const QVariantList &arg)
                                                                                 ^
/usr/lib/qt5/bin/moc -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SQL_LIB -DQT_CORE_LIB --include ./moc_predefs.h -I/usr/lib/qt5/mkspecs/linux-g++ -I/home/giacomo/Progetti/UnicodeSymbolsRunner -I/usr/include/KF5 -I/usr/include/qt5 -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtSql -I/usr/include/KF5/KRunner -I/usr/include/KF5/KService -I/usr/include/KF5/KConfigCore -I/usr/include/KF5/KCoreAddons -I/usr/include/qt5/QtCore -I. -I/usr/include/c++/5.3.1 -I/usr/include/c++/5.3.1/i686-redhat-linux -I/usr/include/c++/5.3.1/backward -I/usr/lib/gcc/i686-redhat-linux/5.3.1/include -I/usr/local/include -I/usr/include ../UnicodeSymbolsRunner/unicodesymbolsrunner.h -o moc_unicodesymbolsrunner.cpp
g++ -c -pipe -g -std=gnu++0x -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SQL_LIB -DQT_CORE_LIB -I../UnicodeSymbolsRunner -I. -isystem /usr/include/KF5 -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtWidgets -isystem /usr/include/qt5/QtGui -isystem /usr/include/qt5/QtSql -isystem /usr/include/KF5/KRunner -isystem /usr/include/KF5/KService -isystem /usr/include/KF5/KConfigCore -isystem /usr/include/KF5/KCoreAddons -isystem /usr/include/qt5/QtCore -I. -I. -I/usr/lib/qt5/mkspecs/linux-g++ -o moc_unicodesymbolsrunner.o moc_unicodesymbolsrunner.cpp
g++  -o UnicodeSymbolsRunner main.o standalonerunner.o dbcreator.o unicodesymbolsrunner.o unicodesymbolsrunner_config.o moc_standalonerunner.o moc_unicodesymbolsrunner.o   -lQt5Widgets -lQt5Gui -lQt5Sql -lKF5Runner -lKF5Service -lKF5ConfigCore -lKF5CoreAddons -lQt5Core -lGL -lpthread
moc_unicodesymbolsrunner.o: In function `qt_noop()':
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: multiple definition of `factory::factory()'
unicodesymbolsrunner.o:/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: first defined here
moc_unicodesymbolsrunner.o: In function `qt_noop()':
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: multiple definition of `factory::factory()'
unicodesymbolsrunner.o:/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: first defined here
moc_unicodesymbolsrunner.o: In function `factory::~factory()':
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: multiple definition of `factory::~factory()'
unicodesymbolsrunner.o:/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: first defined here
moc_unicodesymbolsrunner.o: In function `factory::~factory()':
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: multiple definition of `factory::~factory()'
unicodesymbolsrunner.o:/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: first defined here
moc_unicodesymbolsrunner.o: In function `factory::~factory()':
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: multiple definition of `factory::~factory()'
unicodesymbolsrunner.o:/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: first defined here
moc_unicodesymbolsrunner.o: In function `QObject* KPluginFactory::createInstance<UnicodeSymbolsRunner, QObject>(QWidget*, QObject*, QList<QVariant> const&)':
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: multiple definition of `kde_plugin_version'
unicodesymbolsrunner.o:/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop_Qt_5_6_0_GCC_32_bit_system-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.h:25: first defined here
collect2: error: ld returned 1 exit status
make: *** [UnicodeSymbolsRunner] Error 1
Makefile:166: recipe for target 'UnicodeSymbolsRunner' failed
14:06:25: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project UnicodeSymbolsRunner (kit: Desktop Qt 5.6.0 GCC 32 bit (system))
When executing step "Make"
Bakuriu
Registered Member
Posts
4
Karma
0
Okay, so the problem was that the call to K_EXPORT_PLASMA_RUNNER must be put in the .cpp file and not the .h file (not really sure why though).

However now I have an other problem related to the same macro: it says it is missing the vtable for "factory". The error is:

Code: Select all
g++ -m64 -o UnicodeSymbolsRunner main.o unicodesymbolssearchwindow.o unicodesymbolsrunner.o moc_unicodesymbolssearchwindow.o   -L/usr/X11R6/lib64 -lQt5Widgets -lQt5Gui -lKF5Runner -lKF5Service -lKF5ConfigCore -lKF5CoreAddons -lQt5Core -lGL -lpthread
unicodesymbolsrunner.o: In function `factory::factory()':
Makefile:220: recipe for target 'UnicodeSymbolsRunner' failed
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.cpp:15: undefined reference to `vtable for factory'
unicodesymbolsrunner.o: In function `factory::~factory()':
/home/giacomo/Progetti/build-UnicodeSymbolsRunner-Desktop-Debug/../UnicodeSymbolsRunner/unicodesymbolsrunner.cpp:15: undefined reference to `vtable for factory'
collect2: error: ld returned 1 exit status
make: *** [UnicodeSymbolsRunner] Error 1


where line 15 of unicodesymbolsrunner.cpp contains the call to the abovementioned macro. Can someone tell me what's happening?

I believe vtable errors occur generally when you have virtual methods in the class declaration that don't have an implementation, but I don't think this is the case.
I've also tried to implement every method tagged virtual in AbstractRunner and nothing changes (though I could find only kde4 documentation...)


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]