I read through many questions of the same nature, but didn't find something specific to what I needed.
I am compiling a project on Snow Leopard (10.6.8) and Qt 5.3.2.
In my program's main method I check if it's on mac and bring up a cocoa-based window, otherwise creating the standard QApplication and MainWindow configuration. I have an .mm objective-c class that contains the window code and when include its corresponding header file, it gives me this error:
Undefined symbols for architecture x86_64:
"QMacApplication::QMacApplication()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am using modified code from QT's official github repo for qtmacextras, putting the cocoa window code into its own library which I can import and use in other applications. See https://code.qt.io/cgit/qt/qtmacextras.git/tree/examples/macextras/macfunctions?h=5.14, although I'm using the 5.3.2 compatible commit.
Why am I getting this error?
This error can come from a missing framework as other questions have pointed out.
But the reason for this particular error was that I was missing some lines in my project
profile. I was usingOBJECTIVE_SOURCESto include my.mmfile, but I was not includingOBJECTIVE_HEADERSwith my header file -- even though it didn't contain any objective-c code and I already specified it in theHEADERSdirective.Here's a concise version of my
.profile:It compiles when I remove
qmacapplication.hfrom theHEADERSdirective, but it seems safe to leave it in as well.This is using xcode 4.2 if it matters.