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
Qt Code:
  1. #ifndef _PLUGIN_INTERFACE_
  2. #define _PLUGIN_INTERFACE_
  3.  
  4. #include <QtPlugin>
  5.  
  6. QT_BEGIN_NAMESPACE
  7. class QString;
  8. class QObject;
  9. QT_END_NAMESPACE
  10.  
  11. class PluginInterface {
  12. public:
  13. //virtual ~PluginInterface() {}
  14. virtual void doSomething() = 0;
  15. virtual QString getInfo() = 0;
  16. };
  17. QT_BEGIN_NAMESPACE
  18. Q_DECLARE_INTERFACE(PluginInterface,
  19. "PluginInterface/1.0")
  20. QT_END_NAMESPACE
  21.  
  22. #endif
To copy to clipboard, switch view to plain text mode 

PluginA.h
Qt Code:
  1. #ifndef _PLUGIN_A_
  2. #define _PLUGIN_A_
  3.  
  4. #include "PluginInterface.h"
  5.  
  6. class PluginA: public QObject, public PluginInterface {
  7. Q_OBJECT
  8. Q_INTERFACES(PluginInterface)
  9.  
  10. public:
  11. PluginA();
  12. void doSomething();
  13. QString getInfo();
  14. };
  15. QT_BEGIN_NAMESPACE
  16. Q_EXPORT_PLUGIN2(plugin_a, PluginA)
  17. QT_END_NAMESPACE
  18.  
  19. #endif
To copy to clipboard, switch view to plain text mode 

PluginA.cpp
Qt Code:
  1. #include "PluginA.h"
  2.  
  3. PluginA::PluginA() {
  4. }
  5.  
  6. void PluginA::doSomething() {
  7. }
  8.  
  9. QString PluginA::getInfo() {
  10. return "PluginA";
  11. }
To copy to clipboard, switch view to plain text mode 


The error returned from linker is as follows:
Qt Code:
  1. 1>------ Rebuild All started: Project: plugin_a, Configuration: Release Win32 ------
  2. 1>Build started 9/26/2013 9:53:44 AM.
  3. 1>_PrepareForClean:
  4. 1> Deleting file "release\plugin_a.lastbuildstate".
  5. 1>InitializeBuildStatus:
  6. 1> Touching "release\plugin_a.unsuccessfulbuild".
  7. 1>CustomBuild:
  8. 1> MOC PluginA.h
  9. 1>ClCompile:
  10. 1> PluginA.cpp
  11. 1> moc_PluginA.cpp
  12. 1> Generating Code...
  13. 1>moc_PluginA.obj : error LNK2005: _qt_plugin_query_verification_data already defined in PluginA.obj
  14. 1>moc_PluginA.obj : error LNK2005: _qt_plugin_instance already defined in PluginA.obj
  15. 1> Creating library release\\plugin_a.lib and object release\\plugin_a.exp
  16. 1>release\\plugin_a.dll : fatal error LNK1169: one or more multiply defined symbols found
  17. 1>
  18. 1>Build FAILED.
  19. 1>
  20. 1>Time Elapsed 00:00:02.12
  21. ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
To copy to clipboard, switch view to plain text mode 

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) .Output-Build-plugin_a.zip

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

Thanks in advance.