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. Error: undefined reference to 'vtable for XXX'
Forum Updated to NodeBB v4.3 + New Features

Error: undefined reference to 'vtable for XXX'

Scheduled Pinned Locked Moved General and Desktop
15 Posts 6 Posters 8.6k Views 1 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #5

    So, show the actual error please. My crystal ball is at the repair shop...

    1 Reply Last reply
    0
    • B Offline
      B Offline
      butterface
      wrote on last edited by
      #6

      Do you have virtual methods?

      1 Reply Last reply
      0
      • mranger90M Offline
        mranger90M Offline
        mranger90
        wrote on last edited by
        #7

        Are the above definitions in an include file or a .cpp file ?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kritika
          wrote on last edited by
          #8

          There is no virtual method, right now.
          I am just testing how this concept works.
          And these definitions are include file.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kritika
            wrote on last edited by
            #9

            base.h file
            @#ifndef BASE_H
            #define BASE_H

            #include <QDialog>

            class Base : public QDialog
            {
            Q_OBJECT
            public:

            protected:
            explicit Base(QWidget *parent = 0, Qt::WindowFlags f = 0);

            signals:

            public slots:

            };

            #endif // BASE_H@

            base.cpp file
            @#include "base.h"

            Base::Base(QWidget *parent, Qt::WindowFlags f):
            QDialog(parent, f)
            {
            }@

            Added base.h in PATH: /usr/local/include/ and base.cpp in PATH:/usr/local/src/.., since i dont want to add this base class in my application explicitely.

            TestBase project:
            This is the class inherits Base class:
            test.h file
            @#ifndef TEST_H
            #define TEST_H

            #include "base.h"

            class Test : public Base
            {
            Q_OBJECT

            public:
            explicit Test(QWidget *parent = 0);
            ~Test();

            private:
            };
            #endif // TEST_H
            @

            test.cpp file":
            @#include "test.h"

            Test::Test(QWidget *parent) :
            Base(parent, Qt::FramelessWindowHint ),
            {
            }

            Test::~Test()
            {
            }
            @

            main.cpp:
            @#include <QtGui/QApplication>
            #include "dialog.h"

            int main(int argc, char *argv[])
            {
            QApplication a(argc, argv);
            Dialog w;
            w.show();

            return a.exec&#40;&#41;;
            

            }
            @

            Errors after make command:
            test.o: In function Test::~Test()': test.cpp:(.text+0x1f): undefined reference to vtable for Base'
            test.cpp:(.text+0x27): undefined reference to vtable for Base' test.o: In function Test::Test(QWidget*)':
            test.cpp:(.text+0x96): undefined reference to Base::Base(QWidget*, QFlags<Qt::WindowType>)' test.cpp:(.text+0xee): undefined reference to vtable for Base'
            test.cpp:(.text+0xf6): undefined reference to vtable for Base' moc_test.o: In function Test::qt_metacall(QMetaObject::Call, int, void**)':
            moc_test.cpp:(.text+0x31): undefined reference to Base::qt_metacall(QMetaObject::Call, int, void**)' moc_test.o: In function Test::qt_metacast(char const*)':
            moc_test.cpp:(.text+0x77): undefined reference to Base::qt_metacast(char const*)' moc_test.o:(.rodata+0x20): undefined reference to Base::staticMetaObject'
            moc_test.o:(.rodata._ZTI4Test[typeinfo for Test]+0x10): undefined reference to `typeinfo for Base'
            collect2: ld returned 1 exit status
            make: *** [testMMIBase] Error 1

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #10

              [quote author="Kritika" date="1391494986"]Added base.h in PATH: /usr/local/include/ and base.cpp in PATH:/usr/local/src/.., since i dont want to add this base class in my application explicitely.
              [/quote]
              That is interesting. What do you mean by that? Do you mean that you're not actually compiling in base.h and base.cpp into your application? If so: that won't work. If you don't want Base in your main application, you'll need to put it in a library that you link against. Otherwise, how is your application to know at run time what base actually is?

              1 Reply Last reply
              0
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #11

                If you don't include base.h and base.cpp in your project directory, then they will not be compiled.

                You have two options:

                Put base.h and base.cpp in your project directory.

                Compile base.h and base.cpp into an an external library. Then, link that library to your project.

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  Kritika
                  wrote on last edited by
                  #12

                  @JKSH- Thanks....
                  Like u said, i compiled this base class, this created four versioned libraries:
                  libbase.so
                  libbase.so.1
                  libbase.so.1.0
                  libbase.so.1.0.0
                  and then, i linked the TestBase project against it. The application did build successfully, but giving another error on run:

                  "error while loading shared libraries: libbase.so.1: cannot open shared object file: no such file or directory"

                  Can anybody explain why i am getting this error..

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #13

                    The shared library can't be found. So, you'll need to deploy it to a location where it can be found.

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      Kritika
                      wrote on last edited by
                      #14

                      The problem is fixed..
                      Now, i am adding library in the application by the option Add Library on right click. This is linking library as well as including header file. And this is working well...Although i still couldnt figure out why previous thing was not working.

                      1 Reply Last reply
                      0
                      • JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on last edited by
                        #15

                        [quote author="Kritika" date="1391529236"]The problem is fixed..[/quote]Great! :)

                        [quote]Although i still couldnt figure out why previous thing was not working.[/quote]Because you didn't tell your program where to find the library previously.

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        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