Cannot compile first example of "Qt for Beginners" wiki page
-
Hi,
I've followed the first steps of this guide:
https://wiki.qt.io/Qt_for_BeginnersI've created an Empty qmake Project. I've then put the following code in my .pro file [Snake.pro] (copy-pasted from the guide) :
TEMPLATE = app TARGET = name_of_the_app QT = core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets SOURCES += main.cpp
Then, I made a C++ source file [main.cpp] in which I put (again, copy-pasted):
// #include <QApplication> #include <QPushButton> int main(int argc, char **argv) { QApplication app (argc, argv); QPushButton button ("Hello world !"); button.show(); return app.exec(); } //
When I try to run it, I get the following errors:
D:\OneDrive\Documents\C++\Qt\build-Snake-Desktop_Qt_5_10_0_MSVC2013_64bit-Debug\debug\main.o:-1: In function
Z5qMainiPPc': D:\OneDrive\Documents\C++\Qt\Snake\main.cpp:6: error: undefined reference to
_imp___ZN12QApplicationC1ERiPPci'
D:\OneDrive\Documents\C++\Qt\Snake\main.cpp:8: error: undefined reference to_imp___ZN11QPushButtonC1ERK7QStringP7QWidget' D:\OneDrive\Documents\C++\Qt\Snake\main.cpp:9: error: undefined reference to
_imp___ZN7QWidget4showEv'
D:\OneDrive\Documents\C++\Qt\Snake\main.cpp:8: error: undefined reference to_imp___ZN11QPushButtonD1Ev' [5 to 10 more undefined reference to errors...] crt0_c.c:-1: error: undefined reference to
WinMain@16'
collect2.exe:-1: error: error: ld returned 1 exit statusHow can I fix this? I'm on Windows 10, and the kit I'm using for my project is Desktop Qt 5.10.0 MinGW 32bit with the selected compiler MinGW 5.3.0 32bit for C++.
Thanks!
-
Welcome @Dekeon
Can you try to run a QWidget project?
-
@Dekeon said in Can not compile first example of "Qt for Beginners" wiki page:
I made a Qt Widget and I got the same result, but with a bunch more errors of the same kind:
undefined reference to...Please go to Tools->Options->Build&Run and take a screenshot of the Kits tab
-
Can you add widget in the following way (file .pro)?
QT = core gui widgets
-
@Charlie_Hdz said in Cannot compile first example of "Qt for Beginners" wiki page:
QT = core gui widgets
Tried in both the projects, getting the same errors still.
-
Here is another solution:
You have a mismatch between VS libraries and MINGW... Trying downloading the VS kit from https://www1.qt.io/download/
-
I got the same issue a time ago, having VS and using Qt Creator in the same OS...
Show me the issue description of the kits.
Can you delete all the kits that had issues.
Display the DEsktop MinGW kit and show me the information there. -
Here's the informations about a kit with a red sign:
Here's the one I've selected as default:
I can't seem to be able to delete the ones that are marked red. I've tried the maintenance tool, but I don't know what to de-select and if it's even the right thing to do. Here's my maintenance tool selection screen anyways:
-
@Dekeon said in Cannot compile first example of "Qt for Beginners" wiki page:
What does VS stand for? I don't see anything resembling VS kit to download anywhere.
"VS" stands for "Visual Studio" by Microsoft. It is also known as "MSVC" ("Microsoft Visual C/C++").
If you want to use a VS/MSVC kit, then you need to download Visual Studio from Microsoft. However, since you already have MinGW installed, you can just use the MinGW kit.
@Dekeon said in Cannot compile first example of "Qt for Beginners" wiki page:
I can't seem to be able to delete the ones that are marked red. I've tried the maintenance tool, but I don't know what to de-select and if it's even the right thing to do. Here's my maintenance tool selection screen anyways:
The red exclamation marks are there because you have installed kits that you can't use (for example, you haven't installed MSVC so you can't use the MSVC kits).
Expand "Qt 5.10.0" and untick all the MSVC, UWP, and Android kits. Make sure you leave the MinGW kit installed.
-
To expand @JKSH explanation... I did a test in my rusty Windows (I prefer Linux) with your code. It compiled.
I attached some figures for your reference in the Compiler/Kits configuration. (Qt 5.7.1 (MSVC 2015 32 bits)
Hope your application works.. I remembered that I had issues when I got Qt Creator when I had VS installed. So feel accompanied!
-
Good news, can you set the thread as Solved, please?