Qt 6 undefined reference to `qMain(int, char**)'
- 
I came across a problem and I have no idea what is causing it. I have a project with some library + a number of example apps and tests linking to it and I'm using QMake as build system. 
 When I'm using the combo:Qt 6.6.1 
 MinGW compilerI get undefined reference to `qMain(int, char**)' when building the applications. 
 Any idea what I am doing wrong here?error: D:\Qt\6.6.1\mingw_64\lib\libQt6EntryPoint.a(qtentrypoint_win.cpp.obj):C:/Users/qt/work/qt/qtbase/src/entrypoint/qtentrypoint_win.cpp:50: undefined reference to `qMain(int, char**)' 
- 
I came across a problem and I have no idea what is causing it. I have a project with some library + a number of example apps and tests linking to it and I'm using QMake as build system. 
 When I'm using the combo:Qt 6.6.1 
 MinGW compilerI get undefined reference to `qMain(int, char**)' when building the applications. 
 Any idea what I am doing wrong here?error: D:\Qt\6.6.1\mingw_64\lib\libQt6EntryPoint.a(qtentrypoint_win.cpp.obj):C:/Users/qt/work/qt/qtbase/src/entrypoint/qtentrypoint_win.cpp:50: undefined reference to `qMain(int, char**)' Please show your main.cpp and CMakeLists.txt 
- 
Please show your main.cpp and CMakeLists.txt @Christian-Ehrlicher said in Qt 6 undefined reference to `qMain(int, char**)': Please show your main.cpp and CMakeLists.txt The main function looks like this: 
  I'm using .pro files, which are a lot of stuff 
- 
@Christian-Ehrlicher said in Qt 6 undefined reference to `qMain(int, char**)': Please show your main.cpp and CMakeLists.txt The main function looks like this: 
  I'm using .pro files, which are a lot of stuff Then simplify your code to a minimal example with a proper pro file. 
- 
Then simplify your code to a minimal example with a proper pro file. @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. A '.pro' file looks like this : QT += core gui network serialport xml concurrent sql multimedia multimediawidgets qml svg printsupport greaterThan(QT_MAJOR_VERSION, 5){ 
 QT += core5compat
 }greaterThan(QT_MAJOR_VERSION, 4){ 
 QT += widgets
 TARGET_ARCH=$${QT_ARCH}
 }else{
 TARGET_ARCH=$${QMAKE_HOST.arch}
 }lessThan(QT_MAJOR_VERSION, 6) { 
 win32 {
 QT += axcontainer
 }
 }DEFINES += QT_DEPRECATED_WARNINGS CONFIG += c++17 warn_off debug_and_release object_parallel_to_source CONFIG += resources_big QMAKE_CXXFLAGS += -Wa,-mbig-obj qtHaveModule(opengl): QT += opengl TEMPLATE = app 
 MOC_DIR = $${OUT_PWD}/temp/moc
 RCC_DIR = $${OUT_PWD}/temp/rcc
 UI_DIR = $${OUT_PWD}/temp/ui
 OBJECTS_DIR = $${OUT_PWD}/temp/objDESTDIR = $${INSTALL_PATH} TRANSLATIONS += uc_zh_CN.ts 
 TRANSLATIONS += uc_en_US.tsDefault rules for deployment.qnx: target.path = /tmp/$${TARGET}/bin 
 else: unix:!android: target.path = /opt/$${TARGET}/bin
 !isEmpty(target.path): INSTALLS += targetresources fileRESOURCES += ../x3res.qrc win32:LIBS += -lwinmm ##################################################### 3rd-party##################################################### ads#INCLUDEPATH += ../3rd-party/ads 
 #DEPENDPATH += ../3rd-party/adsacss#INCLUDEPATH += ../3rd-party/acss 
 #DEPENDPATH += ../3rd-party/acss
 DEFINES += "STYLES_DIR=$$PWD/../styles"quazipINCLUDEPATH += $$PWD/../3rd-party/quazip/include 
 DEPENDPATH += $$PWD/../3rd-party/quazip/include
 DEFINES += QUAZIP_STATICLIBS += -L$$PWD/../3rd-party/quazip/lib -lquazip #protobuf 
 #DEFINES += PROTOBUF_USE_DLLS
 LIBS += -L$$PWD/../3rd-party/protobuf/lib -llibprotobuf
 INCLUDEPATH += $$PWD/../3rd-party/protobuf/include
 DEPENDPATH += $$PWD/../3rd-party/protobuf/include#Log4Qt 
 DEFINES += LOG4QT_STATIC #静态编译的LOG4QT必须定义该宏才能正常使用
 LIBS += -L$$PWD/../3rd-party/Log4qt/lib -llog4qt
 INCLUDEPATH += $$PWD/../3rd-party/Log4qt/include
 DEPENDPATH += $$PWD/../3rd-party/Log4qt/includeFFMPEGLIBS += -L$$LIBRARY_PATH -lavutil -lavformat -lavcodec -lavdevice -lavfilter -lswresample -lswscale 
 INCLUDEPATH += $$PWD/../3rd-party/ffmpeg/include
 DEPENDPATH += $$PWD/../3rd-party/ffmpeg/includefftLIBS += -L$$PWD/../3rd-party/fftw/lib -lfftw3 
 INCLUDEPATH += $$PWD/../3rd-party/fftw/include
 DEPENDPATH += $$PWD/../3rd-party/fftw/includeQZXing3DEFINES += ENABLE_ENCODER_GENERIC LIBS += -L$$PWD/../3rd-party/qzxing3/lib -lQZXing3 
 INCLUDEPATH += $$PWD/../3rd-party/qzxing3/include
 DEPENDPATH += $$PWD/../3rd-party/qzxing3/includewindows { 
 # MinGW
 -g++ {
 QMAKE_LFLAGS_WINDOWS += -Wl,--stack,16777216
 }
 # MSVC
 -msvc {
 QMAKE_LFLAGS += /STACK:16777216
 }
 }
- 
Then simplify your code to a minimal example with a proper pro file. @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. 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
- 
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@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.cppWhen 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.cppWhen 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. @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 
- 
There's a conflict between your code and a macro #define main qMaindefined 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 namedmainor reduce/rearrange includes as others have proposed.
- 
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! 
- 
** 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
 
