Abstract plugin inheritance error
-
@kshegunov I tried to add this:
myprojectglobal.h
#ifndef MYPROJECTGLOBAL_HPP #define MYPROJECTGLOBAL_HPP #include <QtCore/qglobal.h> #if defined(MYPROJECT_LIBRARY) # define MYPROJECT_EXPORT Q_DECL_EXPORT #else # define MYPROJECT_EXPORT Q_DECL_IMPORT #endif #endif // MYPROJECTGLOBAL_HPP
DEFINES += MYPROJECT_LIBRARY
plugininterface.hpp
#ifndef PLUGININTERFACE_HPP #define PLUGININTERFACE_HPP #include "myprojectglobal.hpp" #include <QtPlugin> class MYPROJECT_EXPORT PluginInterface { public: virtual ~PluginInterface() {} }; #define PluginInterface_iid "PluginInterface/1.0" Q_DECLARE_INTERFACE(PluginInterface, PluginInterface_iid) #endif // PLUGININTERFACE_HPP
abstractplugin.hpp
#ifndef ABSTRACTPLUGIN_HPP #define ABSTRACTPLUGIN_HPP #include "plugininterface.hpp" class MYPROJECT_EXPORT AbstractPlugin : public QObject, public PluginInterface { Q_OBJECT Q_INTERFACES(PluginInterface) }; #endif // ABSTRACTPLUGIN_HPP
And now I'm getting these errors:
moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl PluginInterface::~PluginInterface(void)" (_imp??1PluginInterface@@UEAA@XZ) referenced in function "int
public: __cdecl PluginFoo::PluginFoo(void)'::
1'::dtor$0" (?dtor$0@?0???0PluginFoo@@QEAA@XZ@4HA)moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl PluginInterface::PluginInterface(void)" (_imp??0PluginInterface@@QEAA@XZ) referenced in function "public: __cdecl PluginFoo::PluginFoo(void)" (??0PluginFoo@@QEAA@XZ)
moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual void * __cdecl AbstractPlugin::qt_metacast(char const *)" (_imp?qt_metacast@AbstractPlugin@@UEAAPEAXPEBD@Z) referenced in function "public: virtual void * __cdecl PluginFoo::qt_metacast(char const *)" (?qt_metacast@PluginFoo@@UEAAPEAXPEBD@Z)
moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual int __cdecl AbstractPlugin::qt_metacall(enum QMetaObject::Call,int,void * *)" (_imp?qt_metacall@AbstractPlugin@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z) referenced in function "public: virtual int __cdecl PluginFoo::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@PluginFoo@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl AbstractPlugin::AbstractPlugin(void)" (_imp??0AbstractPlugin@@QEAA@XZ) referenced in function "public: __cdecl PluginFoo::PluginFoo(void)" (??0PluginFoo@@QEAA@XZ)
moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl AbstractPlugin::~AbstractPlugin(void)" (_imp??1AbstractPlugin@@UEAA@XZ) referenced in function "public: virtual __cdecl PluginFoo::~PluginFoo(void)" (??1PluginFoo@@UEAA@XZ)
moc_pluginfoo.obj:-1: error: LNK2001: unresolved external symbol "__declspec(dllimport) public: static struct QMetaObject const AbstractPlugin::staticMetaObject" (_imp?staticMetaObject@AbstractPlugin@@2UQMetaObject@@B)
....\bin\plugins\pluginfoo.dll:-1: error: LNK1120: 7 unresolved externals
-
@kshegunov I tried to add this:
myprojectglobal.h
#ifndef MYPROJECTGLOBAL_HPP #define MYPROJECTGLOBAL_HPP #include <QtCore/qglobal.h> #if defined(MYPROJECT_LIBRARY) # define MYPROJECT_EXPORT Q_DECL_EXPORT #else # define MYPROJECT_EXPORT Q_DECL_IMPORT #endif #endif // MYPROJECTGLOBAL_HPP
DEFINES += MYPROJECT_LIBRARY
plugininterface.hpp
#ifndef PLUGININTERFACE_HPP #define PLUGININTERFACE_HPP #include "myprojectglobal.hpp" #include <QtPlugin> class MYPROJECT_EXPORT PluginInterface { public: virtual ~PluginInterface() {} }; #define PluginInterface_iid "PluginInterface/1.0" Q_DECLARE_INTERFACE(PluginInterface, PluginInterface_iid) #endif // PLUGININTERFACE_HPP
abstractplugin.hpp
#ifndef ABSTRACTPLUGIN_HPP #define ABSTRACTPLUGIN_HPP #include "plugininterface.hpp" class MYPROJECT_EXPORT AbstractPlugin : public QObject, public PluginInterface { Q_OBJECT Q_INTERFACES(PluginInterface) }; #endif // ABSTRACTPLUGIN_HPP
And now I'm getting these errors:
moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl PluginInterface::~PluginInterface(void)" (_imp??1PluginInterface@@UEAA@XZ) referenced in function "int
public: __cdecl PluginFoo::PluginFoo(void)'::
1'::dtor$0" (?dtor$0@?0???0PluginFoo@@QEAA@XZ@4HA)moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl PluginInterface::PluginInterface(void)" (_imp??0PluginInterface@@QEAA@XZ) referenced in function "public: __cdecl PluginFoo::PluginFoo(void)" (??0PluginFoo@@QEAA@XZ)
moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual void * __cdecl AbstractPlugin::qt_metacast(char const *)" (_imp?qt_metacast@AbstractPlugin@@UEAAPEAXPEBD@Z) referenced in function "public: virtual void * __cdecl PluginFoo::qt_metacast(char const *)" (?qt_metacast@PluginFoo@@UEAAPEAXPEBD@Z)
moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual int __cdecl AbstractPlugin::qt_metacall(enum QMetaObject::Call,int,void * *)" (_imp?qt_metacall@AbstractPlugin@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z) referenced in function "public: virtual int __cdecl PluginFoo::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@PluginFoo@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl AbstractPlugin::AbstractPlugin(void)" (_imp??0AbstractPlugin@@QEAA@XZ) referenced in function "public: __cdecl PluginFoo::PluginFoo(void)" (??0PluginFoo@@QEAA@XZ)
moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl AbstractPlugin::~AbstractPlugin(void)" (_imp??1AbstractPlugin@@UEAA@XZ) referenced in function "public: virtual __cdecl PluginFoo::~PluginFoo(void)" (??1PluginFoo@@UEAA@XZ)
moc_pluginfoo.obj:-1: error: LNK2001: unresolved external symbol "__declspec(dllimport) public: static struct QMetaObject const AbstractPlugin::staticMetaObject" (_imp?staticMetaObject@AbstractPlugin@@2UQMetaObject@@B)
....\bin\plugins\pluginfoo.dll:-1: error: LNK1120: 7 unresolved externals
-
@Defohin Do you link your pluginfoo plugin against the lib containing AbstractPlugin and PluginInterface?
-
Hi,
The usual setup when building a plugin based application is to have the plugin interfaces definitions and related code in a library that you will link to both the plugin and the application.
That's what is suggested here.
-
Hi,
The usual setup when building a plugin based application is to have the plugin interfaces definitions and related code in a library that you will link to both the plugin and the application.
That's what is suggested here.
-
Roughly :
pluginfoo.pro
QT += core gui TARGET = pluginfoo TEMPLATE = lib CONFIG += plugin DESTDIR = $$OUTPWD/bin/plugins LIBS += -L$$OUTPWD/lib -lmycoollib DEFINES += QT_DEPRECATED_WARNINGS INCLUDEPATH += ../mycoollib SOURCES += pluginfoo.cpp HEADERS += pluginfoo.hpp DISTFILES += pluginfoo.json
mycoollib.pro
QT += core gui TARGET = mycoollib TEMPLATE = lib DESTDIR = $$OUTPWD/lib INCLUDEPATH += . SOURCES += \ abstractplugin.cpp HEADERS += \ plugininterface.hpp abstractplugin.hpp
myproject.pro
QT += core gui widgets xml network TARGET = myproject TEMPLATE = app DESTDIR = $$OUTPWD/bin LIBS += -L$$OUTPWD/lib -lmycoollib INCLUDEPATH += ../mycoollib DEFINES += QT_DEPRECATED_WARNINGS SOURCES += src/main.cpp \ gui/myprojectwindow.cpp HEADERS += gui/myprojectwindow.hpp
Project structure
mycoolproject \ ---- mycoollib ---- pluginfoo ---- myproject
mycoolproject being a SUBDIR project building first mycoollib and then pluginfoo and myproject.
-
Roughly :
pluginfoo.pro
QT += core gui TARGET = pluginfoo TEMPLATE = lib CONFIG += plugin DESTDIR = $$OUTPWD/bin/plugins LIBS += -L$$OUTPWD/lib -lmycoollib DEFINES += QT_DEPRECATED_WARNINGS INCLUDEPATH += ../mycoollib SOURCES += pluginfoo.cpp HEADERS += pluginfoo.hpp DISTFILES += pluginfoo.json
mycoollib.pro
QT += core gui TARGET = mycoollib TEMPLATE = lib DESTDIR = $$OUTPWD/lib INCLUDEPATH += . SOURCES += \ abstractplugin.cpp HEADERS += \ plugininterface.hpp abstractplugin.hpp
myproject.pro
QT += core gui widgets xml network TARGET = myproject TEMPLATE = app DESTDIR = $$OUTPWD/bin LIBS += -L$$OUTPWD/lib -lmycoollib INCLUDEPATH += ../mycoollib DEFINES += QT_DEPRECATED_WARNINGS SOURCES += src/main.cpp \ gui/myprojectwindow.cpp HEADERS += gui/myprojectwindow.hpp
Project structure
mycoolproject \ ---- mycoollib ---- pluginfoo ---- myproject
mycoolproject being a SUBDIR project building first mycoollib and then pluginfoo and myproject.
-
You don't link the plugins. You link your plugins against that common library.
Yes, you have to use both
-l
and-L
.-L
just tells the linker where to look at. -
You don't link the plugins. You link your plugins against that common library.
Yes, you have to use both
-l
and-L
.-L
just tells the linker where to look at.@SGaist It works, but I have another question now.
I named the "commonlib" to "pluginmanager" this class will hold information about plugins, load, unload and so on using
QPluginLoader
, but... when I try to use it on the main application including the headerpluginmanager.hpp
it says that it cannot open the file, even if I have theINCLUDEPATH += ../pluginmanager
. On Qt Creator it does work, I'm able to ctrl+click, etc, but when I try to compile I get this error. -
@SGaist It works, but I have another question now.
I named the "commonlib" to "pluginmanager" this class will hold information about plugins, load, unload and so on using
QPluginLoader
, but... when I try to use it on the main application including the headerpluginmanager.hpp
it says that it cannot open the file, even if I have theINCLUDEPATH += ../pluginmanager
. On Qt Creator it does work, I'm able to ctrl+click, etc, but when I try to compile I get this error. -
@Defohin Did you run qmake again after changing the pro file? After qmake you should do a complete rebuild.
@jsulm It works, but now I'm getting unresolved external symbol on the main project when trying to use
PluginManager manager
on theMyProjectWindow
, and I haveLIBS += -L../libs -lpluginmanager
on the pro file.myprojectwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl PluginManager::PluginManager(class QObject *)" (??0PluginManager@@QEAA@PEAVQObject@@@Z) referenced in function "public: __cdecl MyProjectWindow::MyProjectWindow(class QWidget *)" (??0MyProjectWindow@@QEAA@PEAVQWidget@@@Z)
-
@jsulm It works, but now I'm getting unresolved external symbol on the main project when trying to use
PluginManager manager
on theMyProjectWindow
, and I haveLIBS += -L../libs -lpluginmanager
on the pro file.myprojectwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl PluginManager::PluginManager(class QObject *)" (??0PluginManager@@QEAA@PEAVQObject@@@Z) referenced in function "public: __cdecl MyProjectWindow::MyProjectWindow(class QWidget *)" (??0MyProjectWindow@@QEAA@PEAVQWidget@@@Z)
-