PDA

View Full Version : Qt Static Plugin



johnmauer
30th January 2010, 23:54
I am building a static plugin for a Qt application and keep getting the following error message. I'm sure the error is obvious,but I haven't been able to find it. The interface and code are mimics of the example plugin just to test the build. Thanks for any help.


Error 1 error LNK2019: unresolved external symbol "class QObject * __cdecl qt_plugin_instance_juryplugin(void)" (?qt_plugin_instance_juryplugin@@YAPAVQObject@@XZ) referenced in function "public: __thiscall StaticjurypluginPluginInstance::StaticjurypluginPl uginInstance(void)" (??0StaticjurypluginPluginInstance@@QAE@XZ) main.obj Statfit3



#ifndef JURYINTERFACE_H
#define JURYINTERFACE_H

#include <QString>

class JuryInterface
{
public:
virtual ~JuryInterface() {}
virtual QString echo(const QString &message) = 0;
};
Q_DECLARE_INTERFACE(JuryInterface,
"com.geerms.JuryPlugin.JuryInterface/1.0");

#endif


#ifndef JURYPLUGIN_H
#define JURYPLUGIN_H

#include <QtCore>
#include "juryinterface.h"

class JuryPlugin : public QObject,
public JuryInterface
{
Q_OBJECT
Q_INTERFACES(JuryInterface)

public:
QString echo(const QString &message);

};

#endif // JURYPLUGIN_H



#include "juryplugin.h"

QString JuryPlugin::echo(const QString &message)
{
return message;
}

Q_EXPORT_PLUGIN2(juryplugin, JuryPlugin);


the main.cpp has


Q_IMPORT_PLUGIN(juryplugin);

axeljaeger
6th February 2010, 10:23
Does it work when compiling against a dynamic Qt? The error is a linker error and is very likely to be found not in the code. The code already compiled fine when the linker starts its work.

johnmauer
6th February 2010, 12:52
Yes, the problem is with the linking of the library, but occurs in the compiler settings. With the help of Qt support, the problem was resolved by using a .pro file to create the plugin. The Qt menu on Visual Studio has "Open Qt Project File (.pro)" which can create a VS project with the correct includes and pre-processor settings. I had tried to use the QLibrary template and add the proper settings, but failed to get them all, especially QT_STATICPLUGIN and several includes. The Visual Studio Addin does not have a template that will do this. I also found the build to be somewhat sensitive to the order of things, so I have listed them here. (Perhaps this is over kill, but, if it solves the problem for someone else, well worth it. Please note, I quit when it worked, so maybe there are other ways to get the same result.)

juryplugin.pro

TEMPLATE = lib
TARGET = juryplugin
DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS += juryinterface.h juryplugin.h
SOURCES += juryplugin.cpp
CONFIG += plugin static

1. create directory for the plugin under the solution directory and move ,pro file to it (use your own name rather than jury)
2. build interface and plugin files in this directory
3. build plugin, that is, compile (just plugin)
4. modify main.cpp in the application to add

#include <QtPlugin>
#include "..\(plugindirectory)\(plugin)interfaqce.h
QT_IMPORT_PLUGIN((plugin)interface)
5. add dependency in solution so that plugin builds before app
6. in application properties, add library directory to "additional library directories", note this has to be done for both debug and release
7. in application properties, add (plugin).lib to "additional Libraries), again to both compiles
8. build it all