Solved Cannot link Qt static libraries
-
Hi all,
I want to deploy a stand-alone application for Windows 32 bit with MinGW using Qt Creator.
I followed this guide to build Qt statically for Windows (MinGW) and the building process went just fine.
Then, as suggested by the guide, I opened Qt creator and defined a new Kit which uses the new Qt Static version I just built (by linking its qmake.exe). My previously developed project obviously complained (many errors referring to "undefined reference to") when I switched to the other kit that he could not find any reference for the used Qt functions and classes.
In order to tell Qt how to find the libraries I changed the .pro file as follows (I used the Qt UI for linking libraries):
# Project created by QtCreator 2016-09-28T14:09:58 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = String_GUI TEMPLATE = app CONFIG += static SOURCES += main.cpp\ fontdaemon.cpp HEADERS += fontdaemon.h INCLUDEPATH += $$PWD/../../../../Qt/Static/5.7.0/include DEPENDPATH += $$PWD/../../../../Qt/Static/5.7.0/include win32: LIBS += -L$$PWD/../../../../Qt/Static/5.7.0/lib/ -lQt5Core //Example of including one library win32-g++: PRE_TARGETDEPS += $$PWD/../../../../Qt/Static/5.7.0/lib/libQt5Core.a
But even including all the libraries present in the library folder (I put just one for simplicity, but I tried to include all of them), I still get the same number (aboyut 300) of errors "undefined reference to", for example:
C:\Users\Documents\String_GUI\main.cpp:-1: error: undefined reference to `QApplication::QApplication(int&, char**, int)'
It seems my project does not find any reference of the Qt tools in the libraries I link it against. Any insight of what could be the problem?
I have noticed that the static libraries of my Qt static building have the *.a extension instead of the expected (by me) *.lib ; could this be a problem? The compiler anyway does not complain that he cannot find the libraries, so I guess not, but who knows...
Moreover, how can I know which static libraries I need to link my project against, depending on the Qt header files I include for definition?
Thanks in advance.
-
You might be right with your assumption, but the error message you are showing is referring to a constructor which does not exist.
QApplication has an integer and pointers to "strings" (char **). I wonder you got the compilation done with this parameter list. -
The problem is that Qt is not loading at all the static libraries, since none of the objects I use in my application (QLabel, QLineEdit, QFont...) has a reference to. It compiles perfectly by using the Qt version downloaded with the dll's anyway.
-
*.a are libraries compiled with mingw
*.lib are libraries compiled with Visual Studio
QApplication is for graphical I think, so I believe you missed some libraries to link.
try with Qt5Widgets.a and qmain.a.(sorry for my bad english)
-
I tried to link all the libraries present in lib/, include Qt5Widgets and qmain
-
Any hint?
I could have found a problem. When defining the Kit for the Static version of Qt, I get the following warning for the Qt version:
"no qmlscene installed":And then under the kit definition qt tells me that: "The compiler MinGW (x86-windows-msys-pe-32bit) may not produce code compatible with the Qt version (x86-windows-unknown-pe-32bit) installed.
Could this be the cause? -
I found the "super silly" problem. I had two versions of MinGW, and I've built the static version of Qt with one, but was defining the kit with the other one. Now it works fine.