Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Abstract plugin inheritance error

Abstract plugin inheritance error

Scheduled Pinned Locked Moved Solved General and Desktop
23 Posts 4 Posters 10.7k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Defohin
    wrote on last edited by Defohin
    #9

    @kshegunov I tried to add this:

    myprojectglobal.h

    #ifndef MYPROJECTGLOBAL_HPP
    #define MYPROJECTGLOBAL_HPP
    
    #include <QtCore/qglobal.h>
    
    #if defined(MYPROJECT_LIBRARY)
    #  define MYPROJECT_EXPORT Q_DECL_EXPORT
    #else
    #  define MYPROJECT_EXPORT Q_DECL_IMPORT
    #endif
    
    #endif // MYPROJECTGLOBAL_HPP
    

    myproject.pro

    DEFINES += MYPROJECT_LIBRARY
    

    plugininterface.hpp

    #ifndef PLUGININTERFACE_HPP
    #define PLUGININTERFACE_HPP
    
    #include "myprojectglobal.hpp"
    #include <QtPlugin>
    
    class MYPROJECT_EXPORT PluginInterface
    {
    public:
        virtual ~PluginInterface() {}
    };
    
    #define PluginInterface_iid "PluginInterface/1.0"
    
    Q_DECLARE_INTERFACE(PluginInterface, PluginInterface_iid)
    
    #endif // PLUGININTERFACE_HPP
    

    abstractplugin.hpp

    #ifndef ABSTRACTPLUGIN_HPP
    #define ABSTRACTPLUGIN_HPP
    
    #include "plugininterface.hpp"
    
    class MYPROJECT_EXPORT AbstractPlugin : public QObject, public PluginInterface
    {
        Q_OBJECT
        Q_INTERFACES(PluginInterface)
    };
    
    #endif // ABSTRACTPLUGIN_HPP
    

    And now I'm getting these errors:

    moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl PluginInterface::~PluginInterface(void)" (_imp??1PluginInterface@@UEAA@XZ) referenced in function "int public: __cdecl PluginFoo::PluginFoo(void)'::1'::dtor$0" (?dtor$0@?0???0PluginFoo@@QEAA@XZ@4HA)

    moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl PluginInterface::PluginInterface(void)" (_imp??0PluginInterface@@QEAA@XZ) referenced in function "public: __cdecl PluginFoo::PluginFoo(void)" (??0PluginFoo@@QEAA@XZ)

    moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual void * __cdecl AbstractPlugin::qt_metacast(char const *)" (_imp?qt_metacast@AbstractPlugin@@UEAAPEAXPEBD@Z) referenced in function "public: virtual void * __cdecl PluginFoo::qt_metacast(char const *)" (?qt_metacast@PluginFoo@@UEAAPEAXPEBD@Z)

    moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual int __cdecl AbstractPlugin::qt_metacall(enum QMetaObject::Call,int,void * *)" (_imp?qt_metacall@AbstractPlugin@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z) referenced in function "public: virtual int __cdecl PluginFoo::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@PluginFoo@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)

    moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl AbstractPlugin::AbstractPlugin(void)" (_imp??0AbstractPlugin@@QEAA@XZ) referenced in function "public: __cdecl PluginFoo::PluginFoo(void)" (??0PluginFoo@@QEAA@XZ)

    moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl AbstractPlugin::~AbstractPlugin(void)" (_imp??1AbstractPlugin@@UEAA@XZ) referenced in function "public: virtual __cdecl PluginFoo::~PluginFoo(void)" (??1PluginFoo@@UEAA@XZ)

    moc_pluginfoo.obj:-1: error: LNK2001: unresolved external symbol "__declspec(dllimport) public: static struct QMetaObject const AbstractPlugin::staticMetaObject" (_imp?staticMetaObject@AbstractPlugin@@2UQMetaObject@@B)

    ....\bin\plugins\pluginfoo.dll:-1: error: LNK1120: 7 unresolved externals

    jsulmJ 1 Reply Last reply
    0
    • D Defohin

      @kshegunov I tried to add this:

      myprojectglobal.h

      #ifndef MYPROJECTGLOBAL_HPP
      #define MYPROJECTGLOBAL_HPP
      
      #include <QtCore/qglobal.h>
      
      #if defined(MYPROJECT_LIBRARY)
      #  define MYPROJECT_EXPORT Q_DECL_EXPORT
      #else
      #  define MYPROJECT_EXPORT Q_DECL_IMPORT
      #endif
      
      #endif // MYPROJECTGLOBAL_HPP
      

      myproject.pro

      DEFINES += MYPROJECT_LIBRARY
      

      plugininterface.hpp

      #ifndef PLUGININTERFACE_HPP
      #define PLUGININTERFACE_HPP
      
      #include "myprojectglobal.hpp"
      #include <QtPlugin>
      
      class MYPROJECT_EXPORT PluginInterface
      {
      public:
          virtual ~PluginInterface() {}
      };
      
      #define PluginInterface_iid "PluginInterface/1.0"
      
      Q_DECLARE_INTERFACE(PluginInterface, PluginInterface_iid)
      
      #endif // PLUGININTERFACE_HPP
      

      abstractplugin.hpp

      #ifndef ABSTRACTPLUGIN_HPP
      #define ABSTRACTPLUGIN_HPP
      
      #include "plugininterface.hpp"
      
      class MYPROJECT_EXPORT AbstractPlugin : public QObject, public PluginInterface
      {
          Q_OBJECT
          Q_INTERFACES(PluginInterface)
      };
      
      #endif // ABSTRACTPLUGIN_HPP
      

      And now I'm getting these errors:

      moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl PluginInterface::~PluginInterface(void)" (_imp??1PluginInterface@@UEAA@XZ) referenced in function "int public: __cdecl PluginFoo::PluginFoo(void)'::1'::dtor$0" (?dtor$0@?0???0PluginFoo@@QEAA@XZ@4HA)

      moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl PluginInterface::PluginInterface(void)" (_imp??0PluginInterface@@QEAA@XZ) referenced in function "public: __cdecl PluginFoo::PluginFoo(void)" (??0PluginFoo@@QEAA@XZ)

      moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual void * __cdecl AbstractPlugin::qt_metacast(char const *)" (_imp?qt_metacast@AbstractPlugin@@UEAAPEAXPEBD@Z) referenced in function "public: virtual void * __cdecl PluginFoo::qt_metacast(char const *)" (?qt_metacast@PluginFoo@@UEAAPEAXPEBD@Z)

      moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual int __cdecl AbstractPlugin::qt_metacall(enum QMetaObject::Call,int,void * *)" (_imp?qt_metacall@AbstractPlugin@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z) referenced in function "public: virtual int __cdecl PluginFoo::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@PluginFoo@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)

      moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl AbstractPlugin::AbstractPlugin(void)" (_imp??0AbstractPlugin@@QEAA@XZ) referenced in function "public: __cdecl PluginFoo::PluginFoo(void)" (??0PluginFoo@@QEAA@XZ)

      moc_pluginfoo.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl AbstractPlugin::~AbstractPlugin(void)" (_imp??1AbstractPlugin@@UEAA@XZ) referenced in function "public: virtual __cdecl PluginFoo::~PluginFoo(void)" (??1PluginFoo@@UEAA@XZ)

      moc_pluginfoo.obj:-1: error: LNK2001: unresolved external symbol "__declspec(dllimport) public: static struct QMetaObject const AbstractPlugin::staticMetaObject" (_imp?staticMetaObject@AbstractPlugin@@2UQMetaObject@@B)

      ....\bin\plugins\pluginfoo.dll:-1: error: LNK1120: 7 unresolved externals

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #10

      @Defohin Do you link your pluginfoo plugin against the lib containing AbstractPlugin and PluginInterface?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Defohin Do you link your pluginfoo plugin against the lib containing AbstractPlugin and PluginInterface?

        D Offline
        D Offline
        Defohin
        wrote on last edited by
        #11

        @jsulm What you mean? The whole code I have is here.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #12

          Hi,

          The usual setup when building a plugin based application is to have the plugin interfaces definitions and related code in a library that you will link to both the plugin and the application.

          That's what is suggested here.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 1 Reply Last reply
          1
          • SGaistS SGaist

            Hi,

            The usual setup when building a plugin based application is to have the plugin interfaces definitions and related code in a library that you will link to both the plugin and the application.

            That's what is suggested here.

            D Offline
            D Offline
            Defohin
            wrote on last edited by
            #13

            @SGaist I'm really struggling to understand, can you provide an example, please?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by SGaist
              #14

              Roughly :
              pluginfoo.pro

              QT          += core gui
              TARGET       = pluginfoo
              TEMPLATE     = lib
              CONFIG      += plugin
              DESTDIR      = $$OUTPWD/bin/plugins
              LIBS += -L$$OUTPWD/lib -lmycoollib
              DEFINES     += QT_DEPRECATED_WARNINGS
              INCLUDEPATH += ../mycoollib
              SOURCES     += pluginfoo.cpp
              HEADERS     += pluginfoo.hpp
              DISTFILES   += pluginfoo.json
              

              mycoollib.pro

              QT          += core gui
              TARGET       = mycoollib
              TEMPLATE  = lib
              DESTDIR      = $$OUTPWD/lib
              INCLUDEPATH += .
              SOURCES     += \
                  abstractplugin.cpp
              HEADERS     += \
                  plugininterface.hpp
                  abstractplugin.hpp
              
              

              myproject.pro

              QT      += core gui widgets xml network
              TARGET   = myproject
              TEMPLATE = app
              DESTDIR  = $$OUTPWD/bin
              LIBS += -L$$OUTPWD/lib -lmycoollib
              INCLUDEPATH += ../mycoollib
              DEFINES += QT_DEPRECATED_WARNINGS
              SOURCES += src/main.cpp \
                         gui/myprojectwindow.cpp
              
              HEADERS += gui/myprojectwindow.hpp
              

              Project structure

              mycoolproject \
              ---- mycoollib
              ---- pluginfoo
              ---- myproject
              

              mycoolproject being a SUBDIR project building first mycoollib and then pluginfoo and myproject.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              D 1 Reply Last reply
              1
              • SGaistS SGaist

                Roughly :
                pluginfoo.pro

                QT          += core gui
                TARGET       = pluginfoo
                TEMPLATE     = lib
                CONFIG      += plugin
                DESTDIR      = $$OUTPWD/bin/plugins
                LIBS += -L$$OUTPWD/lib -lmycoollib
                DEFINES     += QT_DEPRECATED_WARNINGS
                INCLUDEPATH += ../mycoollib
                SOURCES     += pluginfoo.cpp
                HEADERS     += pluginfoo.hpp
                DISTFILES   += pluginfoo.json
                

                mycoollib.pro

                QT          += core gui
                TARGET       = mycoollib
                TEMPLATE  = lib
                DESTDIR      = $$OUTPWD/lib
                INCLUDEPATH += .
                SOURCES     += \
                    abstractplugin.cpp
                HEADERS     += \
                    plugininterface.hpp
                    abstractplugin.hpp
                
                

                myproject.pro

                QT      += core gui widgets xml network
                TARGET   = myproject
                TEMPLATE = app
                DESTDIR  = $$OUTPWD/bin
                LIBS += -L$$OUTPWD/lib -lmycoollib
                INCLUDEPATH += ../mycoollib
                DEFINES += QT_DEPRECATED_WARNINGS
                SOURCES += src/main.cpp \
                           gui/myprojectwindow.cpp
                
                HEADERS += gui/myprojectwindow.hpp
                

                Project structure

                mycoolproject \
                ---- mycoollib
                ---- pluginfoo
                ---- myproject
                

                mycoolproject being a SUBDIR project building first mycoollib and then pluginfoo and myproject.

                D Offline
                D Offline
                Defohin
                wrote on last edited by
                #15

                @SGaist Do I have to link with -l every single plugin I have? Or I can just provide a path like -L and it's going to work?

                I will try to modify here based on your example.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by SGaist
                  #16

                  You don't link the plugins. You link your plugins against that common library.

                  Yes, you have to use both -land -L.

                  -L just tells the linker where to look at.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  D 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    You don't link the plugins. You link your plugins against that common library.

                    Yes, you have to use both -land -L.

                    -L just tells the linker where to look at.

                    D Offline
                    D Offline
                    Defohin
                    wrote on last edited by
                    #17

                    @SGaist It works, but I have another question now.

                    I named the "commonlib" to "pluginmanager" this class will hold information about plugins, load, unload and so on using QPluginLoader, but... when I try to use it on the main application including the header pluginmanager.hpp it says that it cannot open the file, even if I have the INCLUDEPATH += ../pluginmanager. On Qt Creator it does work, I'm able to ctrl+click, etc, but when I try to compile I get this error.

                    jsulmJ 1 Reply Last reply
                    0
                    • D Defohin

                      @SGaist It works, but I have another question now.

                      I named the "commonlib" to "pluginmanager" this class will hold information about plugins, load, unload and so on using QPluginLoader, but... when I try to use it on the main application including the header pluginmanager.hpp it says that it cannot open the file, even if I have the INCLUDEPATH += ../pluginmanager. On Qt Creator it does work, I'm able to ctrl+click, etc, but when I try to compile I get this error.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by jsulm
                      #18

                      @Defohin Did you run qmake again after changing the pro file? After qmake you should do a complete rebuild.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      D 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @Defohin Did you run qmake again after changing the pro file? After qmake you should do a complete rebuild.

                        D Offline
                        D Offline
                        Defohin
                        wrote on last edited by
                        #19

                        @jsulm It works, but now I'm getting unresolved external symbol on the main project when trying to use PluginManager manager on the MyProjectWindow, and I have LIBS += -L../libs -lpluginmanager on the pro file.

                        myprojectwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl PluginManager::PluginManager(class QObject *)" (??0PluginManager@@QEAA@PEAVQObject@@@Z) referenced in function "public: __cdecl MyProjectWindow::MyProjectWindow(class QWidget *)" (??0MyProjectWindow@@QEAA@PEAVQWidget@@@Z)

                        jsulmJ 1 Reply Last reply
                        0
                        • D Defohin

                          @jsulm It works, but now I'm getting unresolved external symbol on the main project when trying to use PluginManager manager on the MyProjectWindow, and I have LIBS += -L../libs -lpluginmanager on the pro file.

                          myprojectwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl PluginManager::PluginManager(class QObject *)" (??0PluginManager@@QEAA@PEAVQObject@@@Z) referenced in function "public: __cdecl MyProjectWindow::MyProjectWindow(class QWidget *)" (??0MyProjectWindow@@QEAA@PEAVQWidget@@@Z)

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #20

                          @Defohin ../libs is a relative path, are you sure it is correct?
                          Can you post the compiler/linker call just before the error message?
                          As suggested by @SGaist : LIBS += -L$$OUTPWD/lib -lmycoollib (pluginmanager instead of mycoollib)

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          D 1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @Defohin ../libs is a relative path, are you sure it is correct?
                            Can you post the compiler/linker call just before the error message?
                            As suggested by @SGaist : LIBS += -L$$OUTPWD/lib -lmycoollib (pluginmanager instead of mycoollib)

                            D Offline
                            D Offline
                            Defohin
                            wrote on last edited by
                            #21

                            @jsulm I'm using $$OUTPWD now but it still doesn't work.

                            jsulmJ 1 Reply Last reply
                            0
                            • D Defohin

                              @jsulm I'm using $$OUTPWD now but it still doesn't work.

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #22

                              @Defohin Is the resulting path correct and is the lib there?

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • D Offline
                                D Offline
                                Defohin
                                wrote on last edited by Defohin
                                #23

                                It's working now, I forgot to put MYPROJECT_EXPORT on PluginManager class.

                                I love you guys ♥

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved