Getting LNK2019 error on plugin compilation
-
Hello as a newbie to qt, today i tried to create a plugin (.dll file) by following the tutorial on https://www.qcad.org/en/tutorial-creating-a-qcad-plugin
Im using qt creator 3.5.1 Based on Qt 5.5.1 (MSVC 2013, 32 bit) as recommended in https://www.qcad.org/en/qcad-documentation/supported-platforms
However when i try to build the project i get the following error messages, (first picture)RExamplePlugin.obj: -1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl RPluginInfo::RPluginInfo(void)" (_imp??0RPluginInfo@@QEAA@XZ) referenced in function "public: virtual class RPluginInfo __cdecl RExamplePlugin::getPluginInfo(void)" (?getPluginInfo@RExamplePlugin@@UEAA?AVRPluginInfo@@XZ)
RExamplePlugin.obj: -1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl RPluginInfo::set(class QString const &,class QVariant const &)" (_imp?set@RPluginInfo@@QEAAXAEBVQString@@AEBVQVariant@@@Z) referenced in function "public: virtual class RPluginInfo __cdecl RExamplePlugin::getPluginInfo(void)" (?getPluginInfo@RExamplePlugin@@UEAA?AVRPluginInfo@@XZ)
RExamplePlugin.obj: -1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl RPluginInfo::~RPluginInfo(void)" (_imp??1RPluginInfo@@QEAA@XZ) referenced in function "int public: virtual class RPluginInfo __cdecl RExamplePlugin::getPluginInfo(void)'::1'::dtor$0" (?dtor$0@?0??getPluginInfo@RExamplePlugin@@UEAA?AVRPluginInfo@@XZ@4HA)
On the issues screen it says RExamplePlugin.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl RPluginInfo::~RPluginInfo(void)" ..
My files are,
exampleplugin.pro
CONFIG += plugin
TARGET = example
include(C:/qcad-master/shared.pri)HEADERS = RExamplePlugin.h
SOURCES = RExamplePlugin.cpp
TEMPLATE = libDESTDIR = ../../../plugins
LIBS += C:/qcad-master/qcadcore.lib
LIBS += C:/qcad-master/qcadgui.lib
LIBS += C:/qcad-master/qcadecmaapi.libRExamplePlugin.h
#include <QObject>
#include <QScriptEngine>#include "C:/qcad-master/src/core/RPluginInterface.h"
class RExamplePlugin : public QObject, public RPluginInterface
{
Q_OBJECT
Q_INTERFACES(RPluginInterface)public:
virtual bool init() { return true; }
virtual void uninit(bool) {}
virtual void postInit(InitStatus) {}
virtual void initScriptExtensions(QScriptEngine) {}
virtual RPluginInfo getPluginInfo();
virtual bool checkLicense() { return true; }
};RExamplePlugin.cpp
#include "RExamplePlugin.h"
RPluginInfo RExamplePlugin::getPluginInfo() {
RPluginInfo ret;
ret.set("Version", "1.0");
ret.set("ID", "EXAMPLE");
ret.set("Name", "Example Plugin");
ret.set("License", "GPLv3");
ret.set("URL", "http://qcad.org");
return ret;
}#if QT_VERSION < 0x050000
QT_BEGIN_NAMESPACE
Q_EXPORT_PLUGIN2(example, RExamplePlugin)
QT_END_NAMESPACE
#endifwhen i delete the below lines of code from RExamplePlugin.cpp files, the build works without any error but then in QCAD (a qt based cad software) the plugin id,name,version are all unknown. And i got plugin verification error. (as shown in the second picture)
Can someone try to follow those tutorial steps and verify that he can build the .dll file? or let me know about the source of my error
Thanks a lot -
Hello as a newbie to qt, today i tried to create a plugin (.dll file) by following the tutorial on https://www.qcad.org/en/tutorial-creating-a-qcad-plugin
Im using qt creator 3.5.1 Based on Qt 5.5.1 (MSVC 2013, 32 bit) as recommended in https://www.qcad.org/en/qcad-documentation/supported-platforms
However when i try to build the project i get the following error messages, (first picture)RExamplePlugin.obj: -1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl RPluginInfo::RPluginInfo(void)" (_imp??0RPluginInfo@@QEAA@XZ) referenced in function "public: virtual class RPluginInfo __cdecl RExamplePlugin::getPluginInfo(void)" (?getPluginInfo@RExamplePlugin@@UEAA?AVRPluginInfo@@XZ)
RExamplePlugin.obj: -1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl RPluginInfo::set(class QString const &,class QVariant const &)" (_imp?set@RPluginInfo@@QEAAXAEBVQString@@AEBVQVariant@@@Z) referenced in function "public: virtual class RPluginInfo __cdecl RExamplePlugin::getPluginInfo(void)" (?getPluginInfo@RExamplePlugin@@UEAA?AVRPluginInfo@@XZ)
RExamplePlugin.obj: -1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl RPluginInfo::~RPluginInfo(void)" (_imp??1RPluginInfo@@QEAA@XZ) referenced in function "int public: virtual class RPluginInfo __cdecl RExamplePlugin::getPluginInfo(void)'::1'::dtor$0" (?dtor$0@?0??getPluginInfo@RExamplePlugin@@UEAA?AVRPluginInfo@@XZ@4HA)
On the issues screen it says RExamplePlugin.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl RPluginInfo::~RPluginInfo(void)" ..
My files are,
exampleplugin.pro
CONFIG += plugin
TARGET = example
include(C:/qcad-master/shared.pri)HEADERS = RExamplePlugin.h
SOURCES = RExamplePlugin.cpp
TEMPLATE = libDESTDIR = ../../../plugins
LIBS += C:/qcad-master/qcadcore.lib
LIBS += C:/qcad-master/qcadgui.lib
LIBS += C:/qcad-master/qcadecmaapi.libRExamplePlugin.h
#include <QObject>
#include <QScriptEngine>#include "C:/qcad-master/src/core/RPluginInterface.h"
class RExamplePlugin : public QObject, public RPluginInterface
{
Q_OBJECT
Q_INTERFACES(RPluginInterface)public:
virtual bool init() { return true; }
virtual void uninit(bool) {}
virtual void postInit(InitStatus) {}
virtual void initScriptExtensions(QScriptEngine) {}
virtual RPluginInfo getPluginInfo();
virtual bool checkLicense() { return true; }
};RExamplePlugin.cpp
#include "RExamplePlugin.h"
RPluginInfo RExamplePlugin::getPluginInfo() {
RPluginInfo ret;
ret.set("Version", "1.0");
ret.set("ID", "EXAMPLE");
ret.set("Name", "Example Plugin");
ret.set("License", "GPLv3");
ret.set("URL", "http://qcad.org");
return ret;
}#if QT_VERSION < 0x050000
QT_BEGIN_NAMESPACE
Q_EXPORT_PLUGIN2(example, RExamplePlugin)
QT_END_NAMESPACE
#endifwhen i delete the below lines of code from RExamplePlugin.cpp files, the build works without any error but then in QCAD (a qt based cad software) the plugin id,name,version are all unknown. And i got plugin verification error. (as shown in the second picture)
Can someone try to follow those tutorial steps and verify that he can build the .dll file? or let me know about the source of my error
Thanks a lotHi @wodasdsa which compiler are you using? you need exactly the same that was use to build QCad.
And it does not matter which Qt version was used to build Qt Creator, what matters is the Qt version and compiler you use to build the plugin. That can be totally different things ( or even the same)
Regards
-
Hello @aha_1980 thanks a lot for your quick reply,
As you mentioned i checked again my compilers and saw that i used Microsoft Visual C++ Compiler (MSVC) 12.0 (2013) as decleared in https://www.qcad.org/en/qcad-documentation/supported-platforms. You can see the compilers used in the picture.
my compiler
compiler used to build QcadSo im not sure if i got it correctly, did i used the same compiler with the one used to build QCad?
Thanks a lot.
-
Hello @aha_1980 thanks a lot for your quick reply,
As you mentioned i checked again my compilers and saw that i used Microsoft Visual C++ Compiler (MSVC) 12.0 (2013) as decleared in https://www.qcad.org/en/qcad-documentation/supported-platforms. You can see the compilers used in the picture.
my compiler
compiler used to build QcadSo im not sure if i got it correctly, did i used the same compiler with the one used to build QCad?
Thanks a lot.
@wodasdsa So QCAD is build as 64bit version, so you need to build your plugin as 64 bit too.
You'll need MSVC2013 64 bit (which you seem to have, the x86_amd64 version) and a suitable Qt version (can't tell that due to missing screenshot).
Regards
-
Greetings,
I just uninstalled qt and compiler then installed it from https://download.qt.io/archive/qt/5.5/5.5.1/
I tried installing "qt-opensource-windows-x86-msvc2013_64-5.5.1.exe" and while installing i selected msvc2013_64 bit and installed Qt5.5 and msvc2013. On the kits panel i can see that Mscv2013_64 bit is installed but compiler shows 32bit version.While building the plugin, I still get the error message i got in the previous version. And i'm not sure the issue is based on using different bit versions. There is no 64bit qt installer on https://download.qt.io/archive/qt/5.5/5.5.1/ and i can see that qt is compiled with
Architecture: x86_64 (the last pic from my previous post).Could you please try to build the plugin by using your own qt and compiler and let me know about the specs? Cause im pretty sure that i installed the 64bit version of msvc2013 and respective sdk.
Apologies for taking your time and thanks a lot.
-
Greetings,
I just uninstalled qt and compiler then installed it from https://download.qt.io/archive/qt/5.5/5.5.1/
I tried installing "qt-opensource-windows-x86-msvc2013_64-5.5.1.exe" and while installing i selected msvc2013_64 bit and installed Qt5.5 and msvc2013. On the kits panel i can see that Mscv2013_64 bit is installed but compiler shows 32bit version.While building the plugin, I still get the error message i got in the previous version. And i'm not sure the issue is based on using different bit versions. There is no 64bit qt installer on https://download.qt.io/archive/qt/5.5/5.5.1/ and i can see that qt is compiled with
Architecture: x86_64 (the last pic from my previous post).Could you please try to build the plugin by using your own qt and compiler and let me know about the specs? Cause im pretty sure that i installed the 64bit version of msvc2013 and respective sdk.
Apologies for taking your time and thanks a lot.
@wodasdsa
Please show screenshots of you Kits (click on Desktop 5.5.1 ... resp. Desktop (default)) to see how the Kits are set up.
Could you please try to build the plugin by using your own qt and compiler
Unfortunately, no. I neither have Windows nor MSVC :)
-
Here you can see the information about kits,
Do you think these errors are based on using different bit versions? (btw i dont get the error and compile succesfully if i erase getPluginInfo() method from Reaxmpleplugin.cpp file (as i explained in my very first post)
Unfortunately, no. I neither have Windows nor MSVC :)
Oh okey thanks a lot anyways..
-
and the manual desktop (default) panel,
-
any update?
-
Hi,
From the looks of it, you don't export any symbol from your library. This means that, on Windows, the linker won't find them.
-
@SGaist said in Getting LNK2019 error on plugin compilation:
This means that, on Windows, the linker won't find them.
Hello thanks for you answer, to be honest im quite newbie to qt and im not exactly got what you have suggested. You mean the compiler doesnt found qcadcore.lib,qcadgui.lib and qcadecmaapi.lib files in exampleplugin.pro file? And if so how can i solve it?
Thanks a lot for your help -
Did yes, they want to see on them.It's rather that they are not generated because no symbol were exported.
[edit: Something went wrong with the answer SGaist]
-
Sorry what do you mean?
I had .dll files from source code and used this method https://adrianhenke.wordpress.com/2008/12/05/create-lib-file-from-dll/ to create .lib files
-
Sorry what do you mean?
I had .dll files from source code and used this method https://adrianhenke.wordpress.com/2008/12/05/create-lib-file-from-dll/ to create .lib files
@wodasdsa You should read http://doc.qt.io/qt-5/sharedlibrary.html
-
i dont think the problem is in libraries i cant compile without them either..
-
Can you show the relevant header(s) content ?
-
Sure,
to see shared.pri you can check the following link,
https://github.com/qcad/qcad/blob/master/shared.priThanks
-
How can i do that? im newbie to qt and didnt understand most the terms used in that documentation..
-
Just follow the indications in the "Using Symbols from Shared Libraries" part.