Okay, so I’m just starting out with programming Maya plugins in C++. I’m using Qt Creator as my IDE, and as far as getting a working plugin into Maya is concerned, all is well. However, as soon as I try to add in any Qt UI elements, I get a bunch of undefined symbol linker errors. I’m working on the Mac with Maya 2016. I’m 99% sure it’s a toolchain problem, so I won’t waste your time with source code. The actual output is over 2000 lines, so I’m not going to try to paste the whole thing here, but here’s the first few lines, including the g++ invocation:
g++ -headerpad_max_install_names -arch x86_64 -all_load -Xarch_x86_64 -mmacosx-version-min=10.5 -o MayaTest.bundle mayatest.o mayatestgui.o moc_mayatestgui.o -L/Library/Frameworks -bundle -L/Users/kmiller/CPPProjects/TryNumber3/MayaTest/…/…/…/…/…/Applications/Autodesk/maya2016/lib/ -lQtUiTools -L/Users/kmiller/CPPProjects/TryNumber3/MayaTest/…/…/…/…/…/Applications/Autodesk/maya2016/Maya.app/Contents/MacOS -lOpenMaya -lFoundation
Undefined symbols for architecture x86_64:
“qFreeAligned(void*)”, referenced from:
QFormInternal::QAbstractFormBuilder::createDom(QLayout*, QFormInternal::DomLayout*, QFormInternal::DomWidget*) in libQtUiTools.a(abstractformbuilder.o)
QFormInternal::QAbstractFormBuilder::saveTreeWidgetExtraInfo(QTreeWidget*, QFormInternal::DomWidget*, QFormInternal::DomWidget*) in libQtUiTools.a(abstractformbuilder.o)
and so forth. Like I said, over 2000 lines worth.
I’ve removed the core and gui elements from the QT variable, because those are supposed to be referenced in the INCLUDEPATH variable later. As a matter of fact, if I comment that line out, it compiles, but then it crashes Maya when I load it - probably because Maya uses a modified set of libraries and headers for Qt. Here’s what I’m using for my .pro:
TARGET = MayaTest
CONFIG += staticlib
DEFINES += REQUIRE_IOSTREAM _BOOL
QT -= core gui
# stuff for me to edit
SOURCES += mayatest.cpp
mayatestgui.cpp
HEADERS += mayatest.h
mayatestgui.h
FORMS += mayatestgui.ui
# add in the dylib bundle, but remove the dynamic lib
macx: LIBS += -bundle
mac: LIBS -= -dynamiclib
macx: DEFINES += OSMac_
# project definitions for the mac
macx: TARGET = MayaTest.bundle
macx: LIBS += -L$$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/lib/ -lQtUiTools
macx: LIBS += -L$$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/Maya.app/Contents/MacOS -lOpenMaya -lFoundation
macx: INCLUDEPATH += $$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/include/qt
macx: INCLUDEPATH += $$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/include/qt/QtCore
macx: INCLUDEPATH += $$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/include/qt/QtGui
macx: INCLUDEPATH += $$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/include
macx: DEPENDPATH += $$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/include
# remove the app bundle config, since we’re making a lib
macx: CONFIG -= app_bundle
# dependencies for the Qt libraries
macx: PRE_TARGETDEPS += $$PWD/…/…/…/…/…/Applications/Autodesk/maya2016/lib/libQtUiTools.a
So as far as I can tell, I have all of the correct libraries referenced, but apparently, I’m missing something. I did a search through the maya2016 folder for any other libraries, but the only ones I see are for specific plugins like Bifröst and Alembic.
Now, I’m not married to Qt Creator, so if there’s a better way of going around this, please do share. I’d rather not use Xcode if I can avoid it, though, and obviously Visual Studio is out of the question on the Mac.
Any guidance? I want to do the entire plugin in C++, without any elements in a MEL or Python script. This is mostly just to learn how to do it.
EDIT: Currently, I have Qt using the libraries that cause Maya to crash. These are libraries that I built from sources I downloaded from Autodesk’s website, and they’re for Maya 2016, which is what I’m using, so they have to be the right libraries. If I run Maya from the command line, I get a stack trace ending in
QWidget: Must construct a QApplication before a QPaintDevice
However, I’m not even using any GUI elements right now - I’m focusing on getting it to run without crashing. I’m not even referencing any Qt elements anywhere in my code, and I don’t even have the includes, so I don’t know why it’s even touching Qt at the moment.
Also in that stack trace, I get a number of messages about two different libraries:
objc[10383]: Class QNSApplication is implemented in both /Applications/Autodesk/maya2016/Maya.app/Contents/MacOS/QtGui and /Library/Frameworks/QtGui.framework/Versions/4/QtGui. One of the two will be used. Which one is undefined.
I have a feeling this may be part of it, if not the whole thing, but I have no idea how to tell it which library to use.
Any help would be appreciated!
Thanks!