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. Plugin compilation in debug mode
Forum Updated to NodeBB v4.3 + New Features

Plugin compilation in debug mode

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 2.1k 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.
  • K Offline
    K Offline
    Kev The Soundman
    wrote on last edited by
    #1

    I'm using QT version 5.5
    I'm trying to build a plugin based on the Echo plugin example

    However when I try and build my code in Debug configuration I get an error
    Undefined reference to "Vtable for HardwareInterface"

    But when I build it in Release configuration I don't get any errors and the plugin works with my main application which uses QPluginLoader to load it.

    Here is my code
    the interface header file

    #include <QString>
    
    class HardwareInterface
    {
    
    public:
        virtual ~HardwareInterface() {}
    
        virtual int StartInterfacePlugin();
        virtual bool SendData(unsigned char*);
        virtual QString GetLastError();
        virtual void ClosePlugin();
    };
    
    QT_BEGIN_NAMESPACE
    
    #define HardwarePlugin_iid "Lighting.Hardware.HardwareInterface"
    
    Q_DECLARE_INTERFACE(HardwareInterface, HardwarePlugin_iid)
    QT_END_NAMESPACE
    

    The plugin header file

    #include <QtPlugin>
    #include <QString>
    
    #include "hardwareinterface.h"
    
    
    class testplugin : public QObject, HardwareInterface
    {
        Q_OBJECT
        Q_PLUGIN_METADATA(IID HardwarePlugin_iid FILE "testplugin.json")
        Q_INTERFACES(HardwareInterface)
    
    public:
        int StartInterfacePlugin();
        bool SendData(unsigned char*);
        virtual QString GetLastError();
        virtual void ClosePlugin();
    
    private:
        QString ErrorString;
    
    
    };
    

    and the source for the plugin

    #include "testplugin.h"
    
    int testplugin::StartInterfacePlugin()
    {
        return 3;
    }
    
    bool testplugin::SendData(unsigned char *data)
    {
    
        // process data and do what we need with it
        ErrorString="None";
    
        return true;
    }
    
    QString testplugin::GetLastError()
    {
        return ErrorString;
    }
    
    void testplugin::ClosePlugin()
    {
        // do stuff needed to close the plugin
    }
    

    and this is the .pro file

    QT       += core gui
    
    TARGET = $$qtLibraryTarget(testplugin)
    TEMPLATE = lib
    CONFIG += plugin
    
    DESTDIR = plugins
    
    SOURCES += testplugin.cpp
    
    HEADERS += testplugin.h
    DISTFILES += testplugin.json
    
    

    I need to debug my application and QPluginLoader won't allow me to load plugins that are compiled in Release mode.

    I've tried building the EchoPlugin in both Debug and Release configurations and it compiles correctly in boih configurations. I can't see what the difference is.

    Any help would be appreciated.

    kshegunovK 1 Reply Last reply
    0
    • K Kev The Soundman

      I'm using QT version 5.5
      I'm trying to build a plugin based on the Echo plugin example

      However when I try and build my code in Debug configuration I get an error
      Undefined reference to "Vtable for HardwareInterface"

      But when I build it in Release configuration I don't get any errors and the plugin works with my main application which uses QPluginLoader to load it.

      Here is my code
      the interface header file

      #include <QString>
      
      class HardwareInterface
      {
      
      public:
          virtual ~HardwareInterface() {}
      
          virtual int StartInterfacePlugin();
          virtual bool SendData(unsigned char*);
          virtual QString GetLastError();
          virtual void ClosePlugin();
      };
      
      QT_BEGIN_NAMESPACE
      
      #define HardwarePlugin_iid "Lighting.Hardware.HardwareInterface"
      
      Q_DECLARE_INTERFACE(HardwareInterface, HardwarePlugin_iid)
      QT_END_NAMESPACE
      

      The plugin header file

      #include <QtPlugin>
      #include <QString>
      
      #include "hardwareinterface.h"
      
      
      class testplugin : public QObject, HardwareInterface
      {
          Q_OBJECT
          Q_PLUGIN_METADATA(IID HardwarePlugin_iid FILE "testplugin.json")
          Q_INTERFACES(HardwareInterface)
      
      public:
          int StartInterfacePlugin();
          bool SendData(unsigned char*);
          virtual QString GetLastError();
          virtual void ClosePlugin();
      
      private:
          QString ErrorString;
      
      
      };
      

      and the source for the plugin

      #include "testplugin.h"
      
      int testplugin::StartInterfacePlugin()
      {
          return 3;
      }
      
      bool testplugin::SendData(unsigned char *data)
      {
      
          // process data and do what we need with it
          ErrorString="None";
      
          return true;
      }
      
      QString testplugin::GetLastError()
      {
          return ErrorString;
      }
      
      void testplugin::ClosePlugin()
      {
          // do stuff needed to close the plugin
      }
      

      and this is the .pro file

      QT       += core gui
      
      TARGET = $$qtLibraryTarget(testplugin)
      TEMPLATE = lib
      CONFIG += plugin
      
      DESTDIR = plugins
      
      SOURCES += testplugin.cpp
      
      HEADERS += testplugin.h
      DISTFILES += testplugin.json
      
      

      I need to debug my application and QPluginLoader won't allow me to load plugins that are compiled in Release mode.

      I've tried building the EchoPlugin in both Debug and Release configurations and it compiles correctly in boih configurations. I can't see what the difference is.

      Any help would be appreciated.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      @Kev-The-Soundman
      Is this g++?
      If so, try to do both of the following things for your interface:

      1. un-inline the virtual destructor
      2. put a trivial non-inline constructor for your interface.

      PS.
      If your interface doesn't implement the declared virtual methods, then by all means make them pure virtual.

      Read and abide by the Qt Code of Conduct

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

        Hi,

        In addition to @kshegunov . Did you add the Q_OBJECT macro after building your plugin once in debug mode ? If so, re-run qmake and try to rebuild

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

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kev The Soundman
          wrote on last edited by
          #4

          Hi Kshegunov

          I'm using the mingw32 compiler that comes bundles with the QT installation

          Hi SGaist

          The project was built completely from scratch with the Q_OBJECT macro already included.

          It's the fact that it compiles correctly under Release but not under Debug that confuses me.

          I only want to have debug versions so I can debug my main application which uses the plugin.

          kshegunovK 1 Reply Last reply
          0
          • K Kev The Soundman

            Hi Kshegunov

            I'm using the mingw32 compiler that comes bundles with the QT installation

            Hi SGaist

            The project was built completely from scratch with the Q_OBJECT macro already included.

            It's the fact that it compiles correctly under Release but not under Debug that confuses me.

            I only want to have debug versions so I can debug my main application which uses the plugin.

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            @Kev-The-Soundman

            It's the fact that it compiles correctly under Release but not under Debug that confuses me.

            Debug is and should be more strict. You can live without a vtable, but it's a better idea not to have dangling vtable pointers ... so the debug build is properly complaining. Release doesn't care much about errors - there you go for optimizations.

            I'm using the mingw32 compiler that comes bundles with the QT installation

            Basically g++ on tranquilizers. Okay that's actually good. Then see what I wrote and do that:
            First and foremost don't allow to have virtual functions declared without implementing them (like I suspect is the case with your interface).
            And if that doesn't work, make sure you have at least one non-inline function (usually the constructor) before your virtual functions /for further reading on why, you can look here/.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            1
            • K Offline
              K Offline
              Kev The Soundman
              wrote on last edited by
              #6

              kshegunov

              Thanks.

              I'll look at that tonight when I get home.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Kev The Soundman
                wrote on last edited by
                #7

                OK i figured it out.

                There was one subtle difference between my hardwareinterface class and the echointerface class from the echoplugin example.

                in echointerface.h the virtual echo function is declared like this

                virtual QString echo(const Qstring message) =- 0;
                

                but the virtual functions in my hardwareinterface.h were declared like this

                virtual int StartInterfacePlugin();
                    virtual bool SendData(unsigned char*);
                    virtual QString GetLastError();
                    virtual void ClosePlugin();
                

                Adding the =0 to the end of each virtual function declaration fixes the problem.
                i can now compile my plugins in both release and debug mode.

                If someone can explain to me what that does i'd appreciate it.

                kshegunovK 1 Reply Last reply
                0
                • K Kev The Soundman

                  OK i figured it out.

                  There was one subtle difference between my hardwareinterface class and the echointerface class from the echoplugin example.

                  in echointerface.h the virtual echo function is declared like this

                  virtual QString echo(const Qstring message) =- 0;
                  

                  but the virtual functions in my hardwareinterface.h were declared like this

                  virtual int StartInterfacePlugin();
                      virtual bool SendData(unsigned char*);
                      virtual QString GetLastError();
                      virtual void ClosePlugin();
                  

                  Adding the =0 to the end of each virtual function declaration fixes the problem.
                  i can now compile my plugins in both release and debug mode.

                  If someone can explain to me what that does i'd appreciate it.

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by kshegunov
                  #8

                  @Kev-The-Soundman
                  Well, this is what I said in the first place.

                  PS.
                  If your interface doesn't implement the declared virtual methods, then by all means make them pure virtual.

                  and:

                  First and foremost don't allow to have virtual functions declared without implementing them (like I suspect is the case with your interface).

                  = 0 marks that the virtual function is pure-virtual, which means it shall have no implementation (body).

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  1
                  • K Offline
                    K Offline
                    Kev The Soundman
                    wrote on last edited by
                    #9

                    Hi kshegunov

                    It's my first time using virtual functions so the =0 thing to mark them as pure virtual had passed me by.

                    I've now got release and debug versions of my plugins and my program. I'm happy

                    Thanks for your help

                    kshegunovK 1 Reply Last reply
                    0
                    • K Kev The Soundman

                      Hi kshegunov

                      It's my first time using virtual functions so the =0 thing to mark them as pure virtual had passed me by.

                      I've now got release and debug versions of my plugins and my program. I'm happy

                      Thanks for your help

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by
                      #10

                      @Kev-The-Soundman said:

                      It's my first time using virtual functions so the =0 thing to mark them as pure virtual had passed me by.

                      Oh, I see. That explains it. :)

                      I've now got release and debug versions of my plugins and my program. I'm happy
                      Thanks for your help

                      I'm glad it worked out. Happy coding!

                      Read and abide by the Qt Code of Conduct

                      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