0

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

Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89
  • 1
    'Clean all' and try to manually run `qmake` (maybe from the menu in Qt Creator if you use it) – kiwixz Apr 08 '15 at 20:48
  • I am not using QtCreator. I do compile with make -f Makefile.qt myPlugin.bundle and cleaned with make -f Makefile.qt clean. But same issue. Is there a better way to clean in command line ? – Laurent Crivello Apr 08 '15 at 20:54
  • 1
    Notice the **q** in **qmake**, I think you have to run this too. – kiwixz Apr 08 '15 at 20:56
  • The Makefile.qt is actually instructing make to use make (I can see it in the echoed commands). I tried to run it manually, but still same issue. – Laurent Crivello Apr 08 '15 at 20:59
  • Did you defne the createHelix() method in your cpp file and compiled it again? – marcus Apr 08 '15 at 20:51
  • Yes, it's defined. Didn't add it to reduce space in question. void HelixButton::createHelix(bool){}. – Laurent Crivello Apr 08 '15 at 20:53
  • @LaurentCrivello You forgotten to name the bool ? – kiwixz Apr 08 '15 at 20:57
  • Ok, so if each function is defined properly did you try to comment stuff out? Cleaning the project might also help. – marcus Apr 08 '15 at 21:04
  • Following your comment I commented a lot of stuff out and am now down to what is in the question (updated). Always same stuff: without Q_OBJECT it compiles perfect, with Q_OBJECT I get the error. – Laurent Crivello Apr 08 '15 at 21:17

2 Answers2

0

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.

deW1
  • 5,562
  • 10
  • 38
  • 54
  • qmake is executed properly when I don't have Q_OBJECT, so I am not sure this is really the issue; – Laurent Crivello Apr 08 '15 at 21:20
  • Then you're probably missing required definitions in your pro file would you mind showing the full pro. Also check in the full qmake doc how the pro has to be written against your project – deW1 Apr 08 '15 at 21:23
  • Ok, I have updated my question with the full Pro file and qtconfig too. Thanks. – Laurent Crivello Apr 08 '15 at 21:27
  • Where did you define what type of app will be created And qt += qt debug or release for example so on. Please read the full overview link about the project file – deW1 Apr 08 '15 at 21:38
  • When compiling I give as argument myplugin.bundle, so it knows it will be a Maya bundle. Removing Q_OBJECT makes it compile properly, I can execute it into Maya, but the buttons are not responsive. Therefore I think the issue is not really related to type of app. – Laurent Crivello Apr 08 '15 at 21:41
  • By looking a bit more deeply, I found out that no moc is generated for the Q_OBJECT objects. Will need to understand why. – Laurent Crivello Apr 09 '15 at 05:45
0

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

Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89