Qt 6 undefined reference to `qMain(int, char**)'
-
Then simplify your code to a minimal example with a proper pro file.
wrote on 30 Jan 2024, 07:52 last edited by@Christian-Ehrlicher said in Qt 6 undefined reference to `qMain(int, char**)':
Then simplify your code to a minimal example with a proper pro file.
I can compile correctly in qt6.6.0.
-
@Christian-Ehrlicher said in Qt 6 undefined reference to `qMain(int, char**)':
Then simplify your code to a minimal example with a proper pro file.
I can compile correctly in qt6.6.0.
Lifetime Qt Championwrote on 30 Jan 2024, 17:22 last edited by Christian EhrlicherSometimes I wonder if people don't know what minimal means...
This works fine for me with Qt6.6.1/MinGW
#include <QApplication> int main(int argc, char **argv) { QApplication app(argc, argv); return app.exec(); }
TEMPLATE = app TARGET = tmp INCLUDEPATH += . QT += widgets SOURCES += main.cpp
-
Sometimes I wonder if people don't know what minimal means...
This works fine for me with Qt6.6.1/MinGW
#include <QApplication> int main(int argc, char **argv) { QApplication app(argc, argv); return app.exec(); }
TEMPLATE = app TARGET = tmp INCLUDEPATH += . QT += widgets SOURCES += main.cpp
wrote on 31 Jan 2024, 01:27 last edited by@Christian-Ehrlicher said in Qt 6 undefined reference to `qMain(int, char**)':
Sometimes I wonder if people don't know what minimal means...
This works fine for me with Qt6.6.1/MinGW
#include <QApplication> int main(int argc, char **argv) { QApplication app(argc, argv); return app.exec(); }
TEMPLATE = app TARGET = tmp INCLUDEPATH += . QT += widgets SOURCES += main.cpp
When I use the example you provided is normal.
I don't know how to troubleshoot this problem now, because some of my projects can be compiled, and some have this problem.
-
@Christian-Ehrlicher said in Qt 6 undefined reference to `qMain(int, char**)':
Sometimes I wonder if people don't know what minimal means...
This works fine for me with Qt6.6.1/MinGW
#include <QApplication> int main(int argc, char **argv) { QApplication app(argc, argv); return app.exec(); }
TEMPLATE = app TARGET = tmp INCLUDEPATH += . QT += widgets SOURCES += main.cpp
When I use the example you provided is normal.
I don't know how to troubleshoot this problem now, because some of my projects can be compiled, and some have this problem.
Then simplify your projects until it works - a normal devleoper task.
-
Then simplify your projects until it works - a normal devleoper task.
wrote on 1 Feb 2024, 01:22 last edited by@Christian-Ehrlicher said in Qt 6 undefined reference to `qMain(int, char**)':
Then simplify your projects until it works - a normal devleoper task.
Thanks, I think I can get rid of the libraries I'm using and try again
-
wrote on 14 Feb 2024, 07:24 last edited by
Did you solve it?
-
wrote on 7 Mar 2024, 01:40 last edited by
The same problem as you. Have you solved it? Please help me
-
wrote on 4 Apr 2024, 11:48 last edited by
There's a conflict between your code and a macro
#define main qMain
defined ininclude/QtGui/qwindowdefs.h
which is used to avoid a console window in a Qt project (as per https://stackoverflow.com/a/18553402). You can rename any variables in your code namedmain
or reduce/rearrange includes as others have proposed. -
wrote on 26 Oct 2024, 18:57 last edited by
I have encountered the same error with a library I'm using (SDL2). I don't know whether it is the same library that is causing the issue, but for SDL2 I need to put up a macro to tell it that main() is being handled elsewhere (by QT):
#include <QApplication> #define SDL_MAIN_HANDLED #include <SDL2/SDL.h>
Hope it helps!
-
wrote 24 days ago last edited by QtFriend2024
** MY SOLUTION **
I had this same issue with my QT Widgets project using Windows 11 host machine. I had upgraded my QT to 6.8.3 and this Error: undefined reference to `qMain(int, char)'** even though this wasn't the actual issue . Following my steps below, Qt Creator was able to highlight the actual issues for me to resolve and successfully build my project.
Steps to Resolve the Issue:
- Create a new, most simple Qt Widgets project. Use the default mainwindow.h, mainwindow.cpp and mainwindow.ui
with the project kit that you want to use - Run CMake
- Build the project. It should build successfully
- Open the CMakeLists.txt file
- Utilize this new, simple CMakeLists.txt file as a template for your ORIGINAL project.
- Modify the "template" CMakeLists.txt file to include your original project's resource file names where you see main.cpp, mainwindow.h, mainwindow.cpp, etc.
- Modify the "template" CMakeLists.txt file to include the QT packages you are using (Core, Gui, or etc.)
- Modify the "template" CMakeLists.txt file to include the target link libraries (refer to packages in previous step)
- Build your original project
- It should give you more specific, helpful errors to resolve (if there are any). For me, one of my *.cpp files #include Qt Serial Bus but I forgot to add it to CMakeLists.txt
- Resolve errors
- Rebuild. It built successfully for me.
- Create a new, most simple Qt Widgets project. Use the default mainwindow.h, mainwindow.cpp and mainwindow.ui