PDA

View Full Version : Problem with Compiling Low Level API Plugins using Qt 4.8 and Visual Studio 2010



Amr
26th September 2013, 09:27
Hi all,

I writing a Qt plugin (lower level API). I'm using Qt 4.8 and Visual Studio 2010. I came to linker error. and tried to find solution by navigating and searching the internet, but I didn't come to helpful topic. So I tried to write minimal code to ensure that I understood plugins. I created simple Qt project (Qt Add-in 1.1.11 installed) with 3 files (PluginInterface.h, PluginA.h, and PluginA.cpp).


PluginInterface.h


#ifndef _PLUGIN_INTERFACE_
#define _PLUGIN_INTERFACE_

#include <QtPlugin>

QT_BEGIN_NAMESPACE
class QString;
class QObject;
QT_END_NAMESPACE

class PluginInterface {
public:
//virtual ~PluginInterface() {}
virtual void doSomething() = 0;
virtual QString getInfo() = 0;
};
QT_BEGIN_NAMESPACE
Q_DECLARE_INTERFACE(PluginInterface,
"PluginInterface/1.0")
QT_END_NAMESPACE

#endif


PluginA.h


#ifndef _PLUGIN_A_
#define _PLUGIN_A_

#include "PluginInterface.h"

class PluginA: public QObject, public PluginInterface {
Q_OBJECT
Q_INTERFACES(PluginInterface)

public:
PluginA();
void doSomething();
QString getInfo();
};
QT_BEGIN_NAMESPACE
Q_EXPORT_PLUGIN2(plugin_a, PluginA)
QT_END_NAMESPACE

#endif


PluginA.cpp


#include "PluginA.h"

PluginA::PluginA() {
}

void PluginA::doSomething() {
}

QString PluginA::getInfo() {
return "PluginA";
}


The error returned from linker is as follows:


1>------ Rebuild All started: Project: plugin_a, Configuration: Release Win32 ------
1>Build started 9/26/2013 9:53:44 AM.
1>_PrepareForClean:
1> Deleting file "release\plugin_a.lastbuildstate".
1>InitializeBuildStatus:
1> Touching "release\plugin_a.unsuccessfulbuild".
1>CustomBuild:
1> MOC PluginA.h
1>ClCompile:
1> PluginA.cpp
1> moc_PluginA.cpp
1> Generating Code...
1>moc_PluginA.obj : error LNK2005: _qt_plugin_query_verification_data already defined in PluginA.obj
1>moc_PluginA.obj : error LNK2005: _qt_plugin_instance already defined in PluginA.obj
1> Creating library release\\plugin_a.lib and object release\\plugin_a.exp
1>release\\plugin_a.dll : fatal error LNK1169: one or more multiply defined symbols found
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.12
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========


When I tried to compile the some code in Linux Ubuntu, The code compiled and liked successfully.
I tried to enable the options /showIncludes and /VERBOSE, but I don't understand how to prevent symbol duplication in moc_PluginA.obj and PluginA.obj.

In the attachment you can find "Output-Build-plugin_a.zip" which is the console output of Visual Studio (Prevoius two options were set) .9638

I hope I supplied all info you need.
If you need more, please let me know.

Thanks in advance.

anda_skoa
27th September 2013, 08:43
Move Q_EXPORT_PLUGIN2(plugin_a, PluginA) to the .cpp file

Cheers,
_

P.S.: always define a virtual destructor on a class with virtual methods

Amr
29th September 2013, 07:05
YES!!!!!!

Code was compiled successfully.

Many thanks.