Qt 5.3.2 on Mac Snow Leopard: ld: symbol(s) not found for architecture x86_64 [clang, objective-c and c++]

103 Views Asked by At

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?

1

There are 1 best solutions below

0
NuclearPeon On BEST ANSWER

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 pro file. I was using OBJECTIVE_SOURCES to include my .mm file, but I was not including OBJECTIVE_HEADERS with my header file -- even though it didn't contain any objective-c code and I already specified it in the HEADERS directive.

Here's a concise version of my .pro file:

TARGET = QMacApplication
TEMPLATE = lib

QT       += widgets core macextras
QT_PRIVATE += gui-private core-private

QMAKE_CXXFLAGS_GNUCXX11 = -std=c++98
CONFIG -= c++11
load(qt_build_config)

ios {
    LIBS_PRIVATE += -framework UIKit
} else {
    LIBS_PRIVATE += -framework AppKit
}

SOURCES += \
    window.cpp

HEADERS += qmacapplication.h\
        qmacapplication_global.h \
    window.h

OBJECTIVE_SOURCES += qmacapplication.mm
OBJECTIVE_HEADERS += qmacapplication.h

It compiles when I remove qmacapplication.h from the HEADERS directive, but it seems safe to leave it in as well.

This is using xcode 4.2 if it matters.