Results 1 to 3 of 3

Thread: Qt Static Plugin

  1. #1
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Qt Static Plugin

    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
    Qt Code:
    1. #ifndef JURYINTERFACE_H
    2. #define JURYINTERFACE_H
    3.  
    4. #include <QString>
    5.  
    6. class JuryInterface
    7. {
    8. public:
    9. virtual ~JuryInterface() {}
    10. virtual QString echo(const QString &message) = 0;
    11. };
    12. Q_DECLARE_INTERFACE(JuryInterface,
    13. "com.geerms.JuryPlugin.JuryInterface/1.0");
    14.  
    15. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef JURYPLUGIN_H
    2. #define JURYPLUGIN_H
    3.  
    4. #include <QtCore>
    5. #include "juryinterface.h"
    6.  
    7. class JuryPlugin : public QObject,
    8. public JuryInterface
    9. {
    10. Q_OBJECT
    11. Q_INTERFACES(JuryInterface)
    12.  
    13. public:
    14. QString echo(const QString &message);
    15.  
    16. };
    17.  
    18. #endif // JURYPLUGIN_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "juryplugin.h"
    2.  
    3. QString JuryPlugin::echo(const QString &message)
    4. {
    5. return message;
    6. }
    7.  
    8. Q_EXPORT_PLUGIN2(juryplugin, JuryPlugin);
    To copy to clipboard, switch view to plain text mode 

    the main.cpp has

    Qt Code:
    1. Q_IMPORT_PLUGIN(juryplugin);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Qt Static Plugin

    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.
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Static Plugin

    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
    Last edited by johnmauer; 6th February 2010 at 12:56. Reason: typo

Similar Threads

  1. Extending a plugin in a static library
    By ultim8 in forum Qt Programming
    Replies: 5
    Last Post: 25th March 2010, 15:10
  2. Static vs Plugin
    By treyhaslem in forum Newbie
    Replies: 5
    Last Post: 4th December 2009, 14:16
  3. How to use static mysql plugin
    By khikho in forum Qt Programming
    Replies: 7
    Last Post: 19th January 2009, 21:44
  4. Link problems with static MySQL plugin
    By nurtsi in forum Installation and Deployment
    Replies: 4
    Last Post: 20th September 2007, 15:32
  5. Replies: 19
    Last Post: 20th September 2007, 11:56

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.