Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Qt 6 undefined reference to `qMain(int, char**)'
QtWS25 Last Chance

Qt 6 undefined reference to `qMain(int, char**)'

Scheduled Pinned Locked Moved Unsolved Qt 6
14 Posts 6 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HeJianglong
    wrote on last edited by
    #1

    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 compiler

    I 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**)'

    Christian EhrlicherC 1 Reply Last reply
    0
    • H HeJianglong

      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 compiler

      I 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**)'

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Please show your main.cpp and CMakeLists.txt

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      H 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        Please show your main.cpp and CMakeLists.txt

        H Offline
        H Offline
        HeJianglong
        wrote on last edited by
        #3

        @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:
        f6a15c36-9ccf-4824-a151-fc99fa734b8f-image.png

        I'm using .pro files, which are a lot of stuff

        Christian EhrlicherC 1 Reply Last reply
        0
        • H HeJianglong

          @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:
          f6a15c36-9ccf-4824-a151-fc99fa734b8f-image.png

          I'm using .pro files, which are a lot of stuff

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then simplify your code to a minimal example with a proper pro file.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          H 2 Replies Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            Then simplify your code to a minimal example with a proper pro file.

            H Offline
            H Offline
            HeJianglong
            wrote on last edited by
            #5

            @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/obj

            DESTDIR = $${INSTALL_PATH}

            TRANSLATIONS += uc_zh_CN.ts
            TRANSLATIONS += uc_en_US.ts

            Default rules for deployment.

            qnx: target.path = /tmp/$${TARGET}/bin
            else: unix:!android: target.path = /opt/$${TARGET}/bin
            !isEmpty(target.path): INSTALLS += target

            resources file

            RESOURCES += ../x3res.qrc

            win32:LIBS += -lwinmm

            #####################################################

            3rd-party

            #####################################################

            ads

            #INCLUDEPATH += ../3rd-party/ads
            #DEPENDPATH += ../3rd-party/ads

            acss

            #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_STATIC

            LIBS += -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/include

            FFMPEG

            LIBS += -L$$LIBRARY_PATH -lavutil -lavformat -lavcodec -lavdevice -lavfilter -lswresample -lswscale
            INCLUDEPATH += $$PWD/../3rd-party/ffmpeg/include
            DEPENDPATH += $$PWD/../3rd-party/ffmpeg/include

            fft

            LIBS += -L$$PWD/../3rd-party/fftw/lib -lfftw3
            INCLUDEPATH += $$PWD/../3rd-party/fftw/include
            DEPENDPATH += $$PWD/../3rd-party/fftw/include

            QZXing3

            DEFINES += ENABLE_ENCODER_GENERIC

            LIBS += -L$$PWD/../3rd-party/qzxing3/lib -lQZXing3
            INCLUDEPATH += $$PWD/../3rd-party/qzxing3/include
            DEPENDPATH += $$PWD/../3rd-party/qzxing3/include

            windows {
            # MinGW
            -g++ {
            QMAKE_LFLAGS_WINDOWS += -Wl,--stack,16777216
            }
            # MSVC
            -msvc {
            QMAKE_LFLAGS += /STACK:16777216
            }
            }

            1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              Then simplify your code to a minimal example with a proper pro file.

              H Offline
              H Offline
              HeJianglong
              wrote on last edited by
              #6

              @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 EhrlicherC 1 Reply Last reply
              0
              • H HeJianglong

                @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 EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by Christian Ehrlicher
                #7

                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
                

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                H 1 Reply Last reply
                2
                • Christian EhrlicherC 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
                  
                  H Offline
                  H Offline
                  HeJianglong
                  wrote on last edited by
                  #8

                  @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 EhrlicherC 1 Reply Last reply
                  0
                  • H HeJianglong

                    @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 EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Then simplify your projects until it works - a normal devleoper task.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    H 1 Reply Last reply
                    1
                    • Christian EhrlicherC Christian Ehrlicher

                      Then simplify your projects until it works - a normal devleoper task.

                      H Offline
                      H Offline
                      HeJianglong
                      wrote on last edited by
                      #10

                      @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

                      1 Reply Last reply
                      0
                      • Y Offline
                        Y Offline
                        yeontak
                        wrote on last edited by
                        #11

                        Did you solve it?

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          changshou
                          wrote on last edited by
                          #12

                          The same problem as you. Have you solved it? Please help me

                          1 Reply Last reply
                          0
                          • Q Offline
                            Q Offline
                            qt_john_doe
                            wrote on last edited by
                            #13

                            There's a conflict between your code and a macro #define main qMain defined in include/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 named main or reduce/rearrange includes as others have proposed.

                            1 Reply Last reply
                            0
                            • Q Offline
                              Q Offline
                              Q74r3wq-
                              wrote on last edited by
                              #14

                              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!

                              1 Reply Last reply
                              1

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved