未定义的符号vtable

时间:2015-04-08 20:47:24

标签: c++ qt vtable qobject

编译Qt cpp代码并收到此错误:

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.

我的.h文件看起来像:

class HelixButton : public QPushButton
{
    Q_OBJECT

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

和相应的cpp:

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

HelixButton::~HelixButton()
{}

专业版文件包含正确的标题:

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

qtconfig文件的内容:

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

在互联网上阅读多篇文章显示了析构函数声明的问题,但似乎是正确的。

删除Q_OBJECT使其工作,但我真的需要信号。

编译时没有生成moc文件。

有什么可能出错的线索?

谢谢

2 个答案:

答案 0 :(得分:0)

您必须在该文件夹中运行qmake,以便根据您的项目设置由Qt生成makefile

之后你可以运行make。

同样,在运行qmake时,您可能需要指定.pro文件。

检查qmake

documentation

this获取完整概述。

答案 1 :(得分:0)

我的makefile缺少moc生成命令。一旦moc_file.cpp从主cpp文件生成并包含,一切都正确编译。