Qt 6 undefined reference to `qMain(int, char**)'
-
@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 file
RESOURCES += ../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"quazip
INCLUDEPATH += $$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/includeFFMPEG
LIBS += -L$$LIBRARY_PATH -lavutil -lavformat -lavcodec -lavdevice -lavfilter -lswresample -lswscale
INCLUDEPATH += $$PWD/../3rd-party/ffmpeg/include
DEPENDPATH += $$PWD/../3rd-party/ffmpeg/includefft
LIBS += -L$$PWD/../3rd-party/fftw/lib -lfftw3
INCLUDEPATH += $$PWD/../3rd-party/fftw/include
DEPENDPATH += $$PWD/../3rd-party/fftw/includeQZXing3
DEFINES += 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
}
} -
@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 Lifetime Qt Championreplied to HeJianglong on last edited by Christian Ehrlicher
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.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.
-
@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 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. -
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!