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. undefined reference to `vtable for shutdown'
Forum Update on Monday, May 27th 2025

undefined reference to `vtable for shutdown'

Scheduled Pinned Locked Moved Solved General and Desktop
60 Posts 6 Posters 7.8k Views
  • 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.
  • J.HilkJ J.Hilk

    @SPlatten did you make changes in your CMakeLists.txt ?

    I assume you have
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    set (CMAKE_INCLUDE_CURRENT_DIR ON)

    in it ?

    and
    set(PROJECT_SOURCES ....)contains your new class ?
    as well as
    qt5_wrap_cpp qt4_wrap_cpp() (I think that was needed for older version ?)

    SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #17

    @J-Hilk , Unfortunately, still the same result.

    Kind Regards,
    Sy

    J.HilkJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      @J-Hilk , Unfortunately, still the same result.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #18

      @SPlatten Well,

      I'm sorry to say it, but I'm out of ideas. My experience with cmake is very limited and does not reach further :(


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      SPlattenS 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @SPlatten Well,

        I'm sorry to say it, but I'm out of ideas. My experience with cmake is very limited and does not reach further :(

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #19

        @J-Hilk , thanks for your time and efforts.

        Kind Regards,
        Sy

        JoeCFDJ 1 Reply Last reply
        0
        • SPlattenS SPlatten

          @J-Hilk , thanks for your time and efforts.

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #20

          @SPlatten in your source dir where cmake file is located do the following:
          mkdir build
          cd build
          cmake .. -Dyour settings
          make -j4

          Try to build your code in the build folder all the time. In case you have your vtable issues, simply rm -rf * to delete everything in build dir and redo cmake. Do this only in build dir. Be very careful with rm -rf *. You have to have svn or git for your sources.

          SPlattenS 2 Replies Last reply
          0
          • JoeCFDJ JoeCFD

            @SPlatten in your source dir where cmake file is located do the following:
            mkdir build
            cd build
            cmake .. -Dyour settings
            make -j4

            Try to build your code in the build folder all the time. In case you have your vtable issues, simply rm -rf * to delete everything in build dir and redo cmake. Do this only in build dir. Be very careful with rm -rf *. You have to have svn or git for your sources.

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #21

            @JoeCFD , thank you, will give this a go now, I've been doing the following:

            Delete build folder
            Create build folder
            From build folder cmake ${myvariable}
            From build folder make

            I will try using -j4 on the make.

            Kind Regards,
            Sy

            JonBJ 1 Reply Last reply
            0
            • SPlattenS SPlatten

              @JoeCFD , thank you, will give this a go now, I've been doing the following:

              Delete build folder
              Create build folder
              From build folder cmake ${myvariable}
              From build folder make

              I will try using -j4 on the make.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #22

              @SPlatten
              Well make -j4 isn't going to fix anything :)

              Your code looks right to me (especially the Q_OBJECT, whose absence/change can often cause this). Given that you say you have cleaned everything out and rebuilt I am not sure what is wrong (unless there is some artefact left around somewhere it is still seeing).

              From the linker messages undefined reference to vtable for 'shutdown' I am unsure whether it is talking about your class shutdown : public QMainWindow { or the Qt-Designer-generated namespace Ui { class shutdown; } (Ui::shutdown). You might just check what is in the generated ui_shutdown.h file to see if it looks good.... (and if that has not been being regenerated, delete it or update the .ui file to make it regenerate, just in case).

              SPlattenS 1 Reply Last reply
              0
              • JoeCFDJ JoeCFD

                @SPlatten in your source dir where cmake file is located do the following:
                mkdir build
                cd build
                cmake .. -Dyour settings
                make -j4

                Try to build your code in the build folder all the time. In case you have your vtable issues, simply rm -rf * to delete everything in build dir and redo cmake. Do this only in build dir. Be very careful with rm -rf *. You have to have svn or git for your sources.

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #23

                @JoeCFD , same result.

                Kind Regards,
                Sy

                JoeCFDJ 1 Reply Last reply
                0
                • JonBJ JonB

                  @SPlatten
                  Well make -j4 isn't going to fix anything :)

                  Your code looks right to me (especially the Q_OBJECT, whose absence/change can often cause this). Given that you say you have cleaned everything out and rebuilt I am not sure what is wrong (unless there is some artefact left around somewhere it is still seeing).

                  From the linker messages undefined reference to vtable for 'shutdown' I am unsure whether it is talking about your class shutdown : public QMainWindow { or the Qt-Designer-generated namespace Ui { class shutdown; } (Ui::shutdown). You might just check what is in the generated ui_shutdown.h file to see if it looks good.... (and if that has not been being regenerated, delete it or update the .ui file to make it regenerate, just in case).

                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #24

                  @JonB , thank you, here is ui_shutdown.h:

                  #ifndef UI_SHUTDOWN_H
                  #define UI_SHUTDOWN_H
                  
                  #include <QtCore/QVariant>
                  #include <QtGui/QAction>
                  #include <QtGui/QApplication>
                  #include <QtGui/QButtonGroup>
                  #include <QtGui/QHeaderView>
                  #inlcude <QtGui/QLabel>
                  #include <QtGui/QMainWindow>
                  #include <QtGui/QWidget>
                  
                  QT_BEGIN_NAMESPACE
                  
                  class Ui_shutdown
                  {
                  public:
                      QWidget *centralWidget;
                      QLabel *plblText;
                  
                      void setupUi(QMainWindow *shutdown)
                      {
                          if ( shutdown->objectName().isEmpty())
                              shutdown->setObjectName(QString::fromUtf8("shutdown"));
                          shutdown->resize(171, 73);
                          shutdown->setStyleSheet(QString::fromUtf8("background-color: #0790ff;\n"
                  "color:#ffffff;\n"
                  ""));
                          centralWidget = new QWidget(shutdown);
                          centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
                          plblText = new QLabel(centralWidget);
                          plblText->setObjectName(QString::fromUtf8("plblText"));
                          plblText->setGeometry(QRect(0, 0, 171, 71));
                          plblText->setStyleSheet(QString::fromUtf8("vertical-align:middle;\n"
                  "text-align: center;\n"
                  "font-weight: bold;\n"
                  ""));
                          plblText->setAlignment(Qt::AlignCenter);
                          shutdown->setCentralWidget(centralWidget);
                  
                          retranslateUi(shutdown);
                  
                          QMetaObject::connectSlotsByName(shutdown);
                      } // setupUi
                  
                      void retranslateUi(QMainWindow *shutdown)
                      {
                          shutdown->setWindowTitle(QString());
                          plblText->setText(QApplication::translate("shutdown", "Shutting down...", 0, QApplication::UnicodeUTF8));
                      }  // retranslateUi
                  };
                  
                  namespace Ui {
                      class shutdown: public Ui_shutdown {};
                  } // namespace Ui
                  
                  QT_END_NAMESPACE
                  
                  #endif // UI_SHUTDOWN_H
                  

                  Kind Regards,
                  Sy

                  1 Reply Last reply
                  0
                  • SPlattenS SPlatten

                    I am working on a project using Qt 4.8.4, the revision of Qt is something I have no control over. I have added a class one of the libraries which are built with cmake, here is the prototype:

                    shutdown.h:

                    #ifndef SHUTDOWN_H
                    #define SHUTDOWN_H
                    
                    #include <QApplication>
                    #include <QDesktopWidget>
                    #include <QMainWindow>
                    
                    namespace Ui {
                        class shutdown;
                    }
                    
                    class shutdown : public QMainWindow {
                        Q_OBJECT
                    
                    public:
                        explicit shutdown(const char* cpszText, QWidget* pParent = 0);
                        ~shutdown();
                    
                    private:
                        Ui::shutdown* ui;
                    };
                    #endif // SHUTDOWN_H
                    

                    shutdown.cc:

                    #include "shutdown.h"
                    #include "ui_shutdown.h"
                    
                    shutdown::shutdown(const char* cpszText, QWidget* pParent) :
                        QMainWindow(pParent),
                        ui(new Ui::shutdown) {
                        ui->setupUi(this);
                        if ( cpszText ) {
                            ui->plblText->setText(cpszText);
                        }
                    }
                    
                    shutdown::~shutdown() {
                        delete ui;
                    }
                    

                    I've checked CMakeLists.txt which includes the CC file, however when build completes I get:

                    ../../(shutdown.cc.o): In function `shutdown::shutdown(char const*, QWidget*)':
                    shutdown.cc: (.text+0x3a): undefined reference to `vtable for shutdown'
                    shutdown.cc: (.text+0x41): undefined reference to `vtable for shutdown'
                    ../../(shutdown.cc.o): In function `shutdown::~shutdown()':
                    shutdown.cc: (.text+0x4cd): undefined reference to `vtable for shutdown'
                    shutdown.cc: (.text+0x4d4): undefined reference to `vtable for shutdown'
                    collect2: ld returned 1 exit status
                    make[2]: *** [file name] Error 1
                    make[2] Leaving directory 'location'
                    make[1] ** [filename.dir/all] Error 2
                    make[1] Leaving directory 'location'
                    make: *** [all] Error 2
                    
                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #25

                    @SPlatten said in undefined reference to &#x60;vtable for shutdown':

                    ../../(shutdown.cc.o): In function `shutdown::shutdown(char const*, QWidget*)':

                    Note that this .o file is being found in ../.. from where you are/the compiler is being run. Is that indeed correct for you, and where you have deleting files from? Do you by any chance have any other shutdown.cc.o file lying around anywhere from, say, the whole of ../.. downward?

                    I have no experience of " I have added a class one of the libraries which are built with cmake". But when you do a complete rebuild I am expecting you to see among the commands:

                    • A uic run on on shutdown.ui, producing ui_shutdown.h.
                    • A cc (or whatever) compilation run on shutdown.cc, producing shutdown.o.
                    • A cc on moc_shotdown.cc, or similar, producing <can't recall>.
                    • Some kind of ld (or maybe cc) doing the linking. It will involve shutdown.cc.o, I can't remember how moc works, whether there is a moc_shutdown.cc.o or just the moc_shutdown.h or whatever source file.

                    This is not for you to paste the whole output here, it's for you to look at just to verify. It ought be correct anyway.

                    SPlattenS JonBJ 2 Replies Last reply
                    0
                    • SPlattenS SPlatten

                      @JoeCFD , same result.

                      JoeCFDJ Offline
                      JoeCFDJ Offline
                      JoeCFD
                      wrote on last edited by JoeCFD
                      #26

                      @SPlatten ~shutdown() has to be virtual. It is better to start with upper case in your class name(Shutdown). Normally function starts with lower case.
                      also make sure shutdown.cpp is added to cmake file

                          explicit shutdown(const char* cpszText, QWidget* pParent = 0);
                          virtual ~shutdown();
                      
                      JonBJ 1 Reply Last reply
                      0
                      • JoeCFDJ JoeCFD

                        @SPlatten ~shutdown() has to be virtual. It is better to start with upper case in your class name(Shutdown). Normally function starts with lower case.
                        also make sure shutdown.cpp is added to cmake file

                            explicit shutdown(const char* cpszText, QWidget* pParent = 0);
                            virtual ~shutdown();
                        
                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #27

                        @JoeCFD

                        @SPlatten said in undefined reference to &#x60;vtable for shutdown':

                        @J-Hilk . that was the entire class, I've added virtual to the destructor prototype, rebuilding now.

                        @SPlatten
                        Let's be clear: you are now compiling with

                        public:
                            explicit shutdown(const char* cpszText, QWidget* pParent = 0);
                            virtual ~shutdown();
                        

                        right?

                        JoeCFDJ SPlattenS 2 Replies Last reply
                        0
                        • JonBJ JonB

                          @JoeCFD

                          @SPlatten said in undefined reference to &#x60;vtable for shutdown':

                          @J-Hilk . that was the entire class, I've added virtual to the destructor prototype, rebuilding now.

                          @SPlatten
                          Let's be clear: you are now compiling with

                          public:
                              explicit shutdown(const char* cpszText, QWidget* pParent = 0);
                              virtual ~shutdown();
                          

                          right?

                          JoeCFDJ Offline
                          JoeCFDJ Offline
                          JoeCFD
                          wrote on last edited by
                          #28

                          @JonB I did not see that one. Could be the case he changed it and did not save it.

                          1 Reply Last reply
                          0
                          • JonBJ JonB

                            @SPlatten said in undefined reference to &#x60;vtable for shutdown':

                            ../../(shutdown.cc.o): In function `shutdown::shutdown(char const*, QWidget*)':

                            Note that this .o file is being found in ../.. from where you are/the compiler is being run. Is that indeed correct for you, and where you have deleting files from? Do you by any chance have any other shutdown.cc.o file lying around anywhere from, say, the whole of ../.. downward?

                            I have no experience of " I have added a class one of the libraries which are built with cmake". But when you do a complete rebuild I am expecting you to see among the commands:

                            • A uic run on on shutdown.ui, producing ui_shutdown.h.
                            • A cc (or whatever) compilation run on shutdown.cc, producing shutdown.o.
                            • A cc on moc_shotdown.cc, or similar, producing <can't recall>.
                            • Some kind of ld (or maybe cc) doing the linking. It will involve shutdown.cc.o, I can't remember how moc works, whether there is a moc_shutdown.cc.o or just the moc_shutdown.h or whatever source file.

                            This is not for you to paste the whole output here, it's for you to look at just to verify. It ought be correct anyway.

                            SPlattenS Offline
                            SPlattenS Offline
                            SPlatten
                            wrote on last edited by
                            #29

                            @JonB , the only place the shutdown.cc.o exists is off the build directory which I am still deleting completely between rebuilds.

                            Kind Regards,
                            Sy

                            JonBJ 1 Reply Last reply
                            0
                            • JonBJ JonB

                              @JoeCFD

                              @SPlatten said in undefined reference to &#x60;vtable for shutdown':

                              @J-Hilk . that was the entire class, I've added virtual to the destructor prototype, rebuilding now.

                              @SPlatten
                              Let's be clear: you are now compiling with

                              public:
                                  explicit shutdown(const char* cpszText, QWidget* pParent = 0);
                                  virtual ~shutdown();
                              

                              right?

                              SPlattenS Offline
                              SPlattenS Offline
                              SPlatten
                              wrote on last edited by
                              #30

                              @JonB , I've changed these prototypes several times with the same result each time, presently they are:

                              public:
                                  shutdown(const char* cpszText, QWidget *pParent = 0);
                                  ~shutdown();
                              

                              Kind Regards,
                              Sy

                              JoeCFDJ 1 Reply Last reply
                              0
                              • SPlattenS SPlatten

                                @JonB , I've changed these prototypes several times with the same result each time, presently they are:

                                public:
                                    shutdown(const char* cpszText, QWidget *pParent = 0);
                                    ~shutdown();
                                
                                JoeCFDJ Offline
                                JoeCFDJ Offline
                                JoeCFD
                                wrote on last edited by
                                #31

                                @SPlatten this is wrong. You have always to have virtual in front of a destructor. Otherwise, you may have unpleasant memory leak in your apps.

                                SPlattenS 1 Reply Last reply
                                0
                                • SPlattenS SPlatten

                                  @JonB , the only place the shutdown.cc.o exists is off the build directory which I am still deleting completely between rebuilds.

                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by JonB
                                  #32

                                  @SPlatten
                                  I am lost at this point. It might be that one of the experts knows better than I what situation you are in. You would have to wait for them to see this, perhaps later.

                                  At this point, if I were you and I had nothing else to do I would probably take what you have and put it into a brand new, from scratch, standalone tiny project (maybe get rid of the .ui file too) and see if I could get it working as (a) a standalone Qt program (provide a main()) and (b) whatever you are doing for " I have added a class [to] one of the libraries" which I don't know about.

                                  public:
                                      shutdown(const char* cpszText, QWidget *pParent = 0);
                                      ~shutdown();
                                  

                                  I do think you should write virtual ~shutdown(); here, just in case.

                                  SPlattenS 1 Reply Last reply
                                  0
                                  • JoeCFDJ JoeCFD

                                    @SPlatten this is wrong. You have always to have virtual in front of a destructor. Otherwise, you may have unpleasant memory leak in your apps.

                                    SPlattenS Offline
                                    SPlattenS Offline
                                    SPlatten
                                    wrote on last edited by
                                    #33

                                    @JoeCFD , ok, I've changed the constructor so it is prefixed with explicit and the destructor with virtual which goes back to how it was and I still have the same issue.

                                    Kind Regards,
                                    Sy

                                    JoeCFDJ 1 Reply Last reply
                                    0
                                    • JonBJ JonB

                                      @SPlatten
                                      I am lost at this point. It might be that one of the experts knows better than I what situation you are in. You would have to wait for them to see this, perhaps later.

                                      At this point, if I were you and I had nothing else to do I would probably take what you have and put it into a brand new, from scratch, standalone tiny project (maybe get rid of the .ui file too) and see if I could get it working as (a) a standalone Qt program (provide a main()) and (b) whatever you are doing for " I have added a class [to] one of the libraries" which I don't know about.

                                      public:
                                          shutdown(const char* cpszText, QWidget *pParent = 0);
                                          ~shutdown();
                                      

                                      I do think you should write virtual ~shutdown(); here, just in case.

                                      SPlattenS Offline
                                      SPlattenS Offline
                                      SPlatten
                                      wrote on last edited by
                                      #34

                                      @JonB , I believe this issue is because the build process is using just cmake and hasn't been done with Qt Creator. I can't change it, its an old system that is evolving over time.

                                      Kind Regards,
                                      Sy

                                      1 Reply Last reply
                                      0
                                      • SPlattenS Offline
                                        SPlattenS Offline
                                        SPlatten
                                        wrote on last edited by
                                        #35

                                        Just for completeness, here is the actual content of the CMakeLists.txt file:

                                        cmake_minimum_required(VERSION 2.8.10)
                                        include (flexelint) 
                                        
                                        set (CMAKE_AUTOUIC ON)
                                        set (CMAKE_AUTOMOC ON)
                                        set (CMAKE_AUTORCC ON)
                                        set (CMAKE_INCLUDE_CURRENT_DIR ON)
                                        
                                        set (FORMS shutdown_ui)
                                        set (HEADERS shutdown.h
                                                     ui_shutdown.h)
                                        set (sources shutdown.cc)
                                        set (output vip_backend)
                                        add_library(${output} STATIC ${sources})
                                        find_package(Qt4 REQUIRED)
                                        include(${QT_USE_FILE})
                                        foreach(loop_var ${QT_LIBRARIES})
                                          string(REPLACE lib64 lib32 loop_var ${loop_var})
                                          set(QT_LIBRARIES_32 ${QT_LIBRARIES_32} ${loop_var})
                                        endforeach(loop_var)
                                        qt4_wrap_ui(UI_HEADERS ${FORMS})
                                        qt4_wrap_cpp(MOC_SRCS ${HEADERS})
                                        target_link_libraries(${output} ${QT_LIBRARIES_32})
                                        add_flint(${output})
                                        

                                        I have no idea what flexelint is or what it does, same is true of add_flint(${output}).

                                        Kind Regards,
                                        Sy

                                        Christian EhrlicherC 1 Reply Last reply
                                        0
                                        • SPlattenS SPlatten

                                          @JoeCFD , ok, I've changed the constructor so it is prefixed with explicit and the destructor with virtual which goes back to how it was and I still have the same issue.

                                          JoeCFDJ Offline
                                          JoeCFDJ Offline
                                          JoeCFD
                                          wrote on last edited by JoeCFD
                                          #36

                                          @SPlatten forget about Qt Creator. Try to build it from command line
                                          Delete build folder
                                          Create build folder
                                          From build folder cmake ${myvariable}
                                          From build folder make VERBOSE=1
                                          add verbose to see more build details.

                                          SPlattenS 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