Nominate our 2022 Qt Champions!

Undefined reference to library after static compiling qt

  • Hey,
    i compiled qt for windows static wothout any error and if i compile and execute a programm with qt creator without libs it is working. But if i want to use the Qt libs and include them, it says i.e QCoreApplication was not declared. After adding them in the*.pro file it says undefined reference to them.

    *.pro file

    Project created by QtCreator 2013-12-20T10:42:53


    QT += core

    QT -= gui

    TARGET = untitled1
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app
    LIBS += -LC:\qt-everywhere-opensource-src-5.2.0_14Versuch\qtbase\lib -lQt5Core
    INCLUDEPATH += C:\qt-everywhere-opensource-src-5.2.0_14Versuch\qtbase\include\QtCore

    SOURCES += main.cpp

    #include <QCoreApplication>
    using namespace std;
    int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);

    return a.exec(&#41;;


    Can anybody help me?

  • Moderators

    first you need to add the following line to your .pro file
    @CONFIG += static@

    And also note that you need to rerun qmake everytime you alter the .pro file.

  • Thx for your answer.

    i added the CONFIG+=static in the project settings in additional arguments, but i can do it in the Pro file again.
    I saw that the #include<QCoreApplication> refers to my standart qt under c: Qt5.2/...
    how can i change this?

    This is my error:
    13:30:12: Führe Schritte für Projekt untitled1 aus...
    13:30:12: Starte "C:\Sourcery_standard\bin\make.exe" clean
    rm -f main.obj
    C:\Sourcery_standard\bin\make.exe: Interrupt/Exception caught (code = 0xc00000fd, addr = 0x4227d3)
    13:30:12: Der Prozess "C:\Sourcery_standard\bin\make.exe" wurde mit dem Rückgabewert 255 beendet.
    13:30:12: Unveränderte Konfiguration, qmake-Schritt wird übersprungen.
    13:30:12: Starte "C:\Sourcery_standard\bin\make.exe"
    C:\Sourcery_standard\bin\arm-none-linux-gnueabi-g++.exe -c -pipe -march=armv7-a -mtune=cortex-a8 -mthumb -mfpu=neon -mfloat-abi=soft -g -Wall -W -D_REENTRANT -fPIE -DQT_STATIC_BUILD -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_CORE_LIB -I..\qt-everywhere-opensource-src-5.2.0_14Versuch\qtbase\mkspecs\linux-arm-gnueabi-g++ -I..\untitled1 -I..\qt-everywhere-opensource-src-5.2.0_14Versuch\qtbase\include -I..\qt-everywhere-opensource-src-5.2.0_14Versuch\qtbase\include\QtCore -I. -I. -o main.obj ..\untitled1\main.cpp
    C:\Sourcery_standard\bin\arm-none-linux-gnueabi-g++.exe -static -static-libgcc -o untitled1 main.obj -LC:/qt-everywhere-opensource-src-5.2.0_14Versuch/qtbase/lib -lQt5Core -lpthread
    main.obj: In function main': C:\build-untitled1-static-Debug/..\untitled1/main.cpp:6: undefined reference toQCoreApplication::QCoreApplication(int&, char**, int)'
    C:\build-untitled1-static-Debug/..\untitled1/main.cpp:8: undefined reference to QCoreApplication::exec&#40;&#41;' C:\build-untitled1-static-Debug/..\untitled1/main.cpp:8: undefined reference toQCoreApplication::~QCoreApplication()'
    C:\build-untitled1-static-Debug/..\untitled1/main.cpp:8: undefined reference to `QCoreApplication::~QCoreApplication()'
    collect2.exe: error: ld returned 1 exit status
    make: *** [untitled1] Error 1
    13:30:14: Der Prozess "C:\Sourcery_standard\bin\make.exe" wurde mit dem Rückgabewert 2 beendet.
    Fehler beim Erstellen/Deployment des Projekts untitled1(Kit: static )
    Bei der Ausführung von Schritt 'Make'
    13:30:14: Verstrichene Zeit: 00:02.

  • Moderators

    check your qt creator settings.
    Or if you use the command prompt make sure your environment variables are pointing to correct qt installation.

  • which settings can i check? the environment variables are ok and i get the same error in command prompt as in qt creator.

    i noticed that the include< offers files depending on the projectpath, but there is no Q... as proposal

  • Moderators

    QTDIR, etc.
    just check all of them to make sure ;)

  • They seem to be ok. No path to the old(normal) qt-version.

    Maybe i built qt wrong?
    here is my command:
    C:\qt-everywhere-opensource-src-5.2.0_14Versuch\qtbase>configure -embedded -platform win32-g++ -xplatform linux-arm-gnueabi-g++ -no-angle -opengl desktop -static -opensource -nomake examples


    qmake configuration for building with arm-linux-gnueabi-g++

    CONFIG += incremental gdb_dwarf_index


    modifications to g++.conf

    QMAKE_CC = C:\Sourcery_standard\bin\arm-none-linux-gnueabi-gcc.exe
    QMAKE_CXX = C:\Sourcery_standard\bin\arm-none-linux-gnueabi-g++.exe
    QMAKE_LINK = C:\Sourcery_standard\bin\arm-none-linux-gnueabi-g++.exe
    QMAKE_LINK_SHLIB = C:\Sourcery_standard\bin\arm-none-linux-gnueabi-g++.exe

    modifications to linux.conf

    QMAKE_AR = C:\Sourcery_standard\bin\arm-none-linux-gnueabi-ar.exe cqs
    QMAKE_OBJCOPY = C:\Sourcery_standard\bin\arm-none-linux-gnueabi-objcopy.exe
    QMAKE_NM = C:\Sourcery_standard\bin\arm-none-linux-gnueabi-nm.exe -P
    QMAKE_STRIP = C:\Sourcery_standard\bin\arm-none-linux-gnueabi-strip.exe
    COMPILER_FLAGS = -march=armv7-a -mtune=cortex-a8 -mthumb -mfpu=neon -mfloat-abi=soft

    QMAKE_CFLAGS_RELEASE = -Os -momit-leaf-frame-pointer
    QMAKE_LFLAGS = -static -static-libgcc


    LFLAGS = -static -static-libgcc


    do i need to set qt.conf?

  • I still have the problem... Can't andybody help me?

  • I get the same problem also if i compile non-static...

  • if i compile it on a second Computer the same error appears.
    I dont know how to solve this ...

  • This is my PATH variable:
    PATH=C:\Program Files\Business Objects\Common\3.5\bin\NOTES;C:\Program Files\Bu
    siness Objects\Common\3.5\bin\NOTES\DATA;C:\Windows\system32;C:\Windows;C:\Wind
    C:\qt-everywhere-opensource-src-5.2.0_14Versuch\qtbase\bin;C:\Sourcery_standard\bin;C:\Program Files\Business Objects\Common\3.5\bin\NOTES;C:\Program Files\Business Objects\Common\3.5\bin\NOTES\DATA;C:\Windows\system32;C:\Windows;C:\GnuWin32\bin;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\


Log in to reply