Important: Please read the Qt Code of Conduct -

Unable to build my first QT Application

  • Hi all,

    I'm new to developing with QT, but I'd like to develop c++ application using this framework.

    Since I'm blind and QT Creator has some important accessibility issues in Mac OS X, I thought I could develop QT-Based applications using the QMake command line tool. However, I am not able to build my first application. Running QMake to generate the makefile doesn't give me any warning nor error, but running the make command I get the following output:

    /Applications/ -headerpad_max_install_names -Wl,-syslibroot,/Applications/ -mmacosx-version-min=10.6 -o -F/Users/my_username/Downloads/qt_src/qtbase/lib -framework QtGui -framework QtCore -framework OpenGL -framework AGL
    Undefined symbols for architecture x86_64:
    "_main", referenced from:
    start in crt1.10.6.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [] Error 1

    The app is named ts. Here's the file content:

    TEMPLATE = app
    TARGET = ts
    QT = core gui
    sources += main.cpp

    And here's my very very simple main.cpp content:
    #include <QApplication>

    using namespace std;

    int main(int argc, char* *argv) {
    QApplication myApp(argc, argv);

    After running make, I get an app bundle, but I cannot run it; Mac OS X tells me that it is damaged or incomplete and, in fact, it misses the main executable.

    I'm running Mac OS X 10.9.2; I'm using QT 5.2.1 and I have installed Xcode 5.1. Not sure if this is important, but since the QT Installer is not accessible, I built QT from source.

    Any help is very appreciated, since I don't know what to do to solve the problem. Thanks in advance.

  • sources keyword should be all CAPITAL

    TEMPLATE = app
    TARGET = ts
    QT = core gui
    SOURCES += main.cpp

  • Hi andreyc,

    thank you very much for your help. I really didn't notice that. :-)

    Now I'm getting another error, though; when I run make, it tells me that it cannot find the QApplication file. So I guess QMake doesn't know where the QT libraries are; how can I supply this information, so that it can find the needed files?

  • QApplication is a part of QWidgets framework
    see here "the list of all modules in Qt5": that qmake will recognize.

    to make QApplication visible to qmake set QT += widgets
    TEMPLATE = app
    TARGET = ts
    QT += widgets
    SOURCES += main.cpp

  • Hi andreyc,

    once again, thank you very much. I finally got my first QT Application running on Mac OS X! :-)

    I could never immagine that QT core and QT GUI weren't enough to get the QApplication file; in fact, I wrote the pro file following this tutorial:

    Is there any way to report that the documentation is incorrect?

  • Lifetime Qt Champion


    This article might have been written with Qt 4 in mind. Anyway I've updated it so it's also valid for Qt 5.

  • Hi falcon03,
    The images in your page are not available.

    You don't need to assign QT to gui and core, these modules are included by default. In fact if you want to create a console application or a library then you have to disable gui module
    QT -= gui

Log in to reply