Results 1 to 3 of 3

Thread: Problem with Compiling Low Level API Plugins using Qt 4.8 and Visual Studio 2010

  1. #1
    Join Date
    Sep 2013
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Problem with Compiling Low Level API Plugins using Qt 4.8 and Visual Studio 2010

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with Compiling Low Level API Plugins using Qt 4.8 and Visual Studio 2010

    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

  3. #3
    Join Date
    Sep 2013
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with Compiling Low Level API Plugins using Qt 4.8 and Visual Studio 2010

    YES!!!!!!

    Code was compiled successfully.

    Many thanks.

Similar Threads

  1. QtService start problem visual studio 2010
    By matteo.ceruti in forum Qt Programming
    Replies: 2
    Last Post: 24th December 2012, 09:22
  2. Replies: 2
    Last Post: 26th November 2012, 08:09
  3. Replies: 4
    Last Post: 13th November 2012, 21:46
  4. Qt add in Visual Studio 2010 problem
    By qtmude in forum Installation and Deployment
    Replies: 2
    Last Post: 18th January 2012, 14:41
  5. Problem compiling QT 4,8,0 in windows 7 x64 with visual studio 2010
    By phate89 in forum Installation and Deployment
    Replies: 0
    Last Post: 11th January 2012, 17:14

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.