简体   繁体   中英

Undefined symbol vtable

Compiling Qt cpp code and receiving this error:

Running ld for x86_64 ...
Undefined symbols for architecture x86_64:
  "vtable for HelixButton", referenced from:
      HelixButton::HelixButton(QString const&, QWidget*) in helixQtCmd.o
      HelixButton::HelixButton(QString const&, QWidget*) in helixQtCmd.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.

my .h file looks like:

class HelixButton : public QPushButton
{
    Q_OBJECT

public:
            HelixButton(const QString& text, QWidget* parent = 0);
    virtual ~HelixButton();
};

and the corresponding cpp:

HelixButton::HelixButton(const QString& text, QWidget* parent)
:   QPushButton(text, parent)
{}

HelixButton::~HelixButton()
{}

The pro file contains the proper header:

include(qtconfig)
    INCLUDEPATH += /Users/laurent/Dropbox/Dev/Maya/qt/include
    INCLUDEPATH += /Users/laurent/Dropbox/Dev/Maya/qt/include/QtGui
    INCLUDEPATH += /Users/laurent/Dropbox/Dev/Maya/qt/include/QtCore
    INCLUDEPATH += /Users/laurent/Dropbox/Dev/Maya/qt/include/QtUiTools

TARGET = helixQtCmd
HEADERS += helixQtCmd.h
SOURCES += helixQtCmd.cpp

Contents of the qtconfig file:

TEMPLATE = lib
CONFIG -= debug
CONFIG += qt warn_on plugin

_DEVKIT_LOCATION = $$(MAYA_LOCATION)/../../devkit
_MAYA_INCLUDE_DIR = $${_DEVKIT_LOCATION}/include

DEFINES     += CC_GNU_ OSMac_ OSMacOSX_ Bits32_  REQUIRE_IOSTREAM \
            OSMac_MachO_ _LANGUAGE_C_PLUS_PLUS 
INCLUDEPATH += .. "$${_MAYA_INCLUDE_DIR}"
TARGET_EXT  = bundle
QMAKE_EXTENSION_SHLIB   = bundle

QMAKE_CC    = clang
QMAKE_CXX   = clang++

_CFLAGS     = -O3 -include "$${_MAYA_INCLUDE_DIR}/maya/OpenMayaMac.h"
QMAKE_CFLAGS    += $${_CFLAGS}

QMAKE_CXXFLAGS  += $${_CFLAGS} -stdlib=libstdc++ $(WARNFLAGS) $(ERROR_FLAGS) \
            -fno-gnu-keywords -fpascal-strings

_DYNLIB_LOCATION    = $$(MAYA_LOCATION)/MacOS
_LREMAP         = -Wl,-executable_path,"$${_DYNLIB_LOCATION}"

LIBS        += -L"$${_DYNLIB_LOCATION}" $${_LREMAP} -lOpenMaya -lFoundation \
            -framework System -framework CoreServices \
            -framework SystemConfiguration \
            -framework Carbon -framework Cocoa \
            -framework ApplicationServices \
            -framework IOKit \
            -framework QtCore \
            -framework QtGui

QMAKE_LFLAGS    += -stdlib=libstdc++ -fno-gnu-keywords -fpascal-strings  \
            -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -bundle

QMAKE_LINK      = $${QMAKE_CXX}
QMAKE_MAC_SDK   = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk

MAKEFILE = $${TARGET}.mak

Reading multiple articles on internet show an issue with the destructor declaration, but it seems correct.

Removing Q_OBJECT makes it work, but i really need signals.

No moc file is generated upon compilation.

Any clue what could go wrong ?

Thanks

You have to run qmake in that folder for the makefile to be generated by Qt according to your project settings.

After that you can run make.

Also when running qmake you might need to specify the .pro file.

Check the documentation of qmake

And this for a full overview.

My makefile was missing a moc generation command. Once moc_file.cpp generated and included from the main cpp file, everything compiles properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM