Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to solve the undefined reference to `WinMain' error for links made on command line?
Forum Updated to NodeBB v4.3 + New Features

How to solve the undefined reference to `WinMain' error for links made on command line?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 10.8k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    Kev_
    wrote on last edited by
    #1

    Hi everyone,

    I'm doing a test. I have created an empty qmake project with Qt creator. I added a file main.cpp. A small code in main.cpp just displays a button. I want to use the created main.o file to build the obtained application in Qt Creator. For this, I make links between the main.o file and the libraries indicated in the Makefile.Debug file. I do it in command line and I use mingw_64 Version 12.2.0 (not the one in the Qt folder) to make the links.
    The command I use is the following:

    g++ main.o -LC:\Qt\6.4.0\mingw_64\lib -lQt6Widgets -lQt6Gui -lQt6Core -lQt6EntryPoint -o executabl_test
    

    I get the following error:

    undefined reference to `WinMain'
    

    the complete output is the following:

    C:/x86_64-12.2.0-release-posix-seh-rt_v10-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/x86_64-12.2.0-release-posix-seh-rt_v10-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
    collect2.exe: error: ld returned 1 exit status
    

    I also noticed that with or without the Qt6EntryPoint library I get the same error.
    I would like to know please what is the source of the problem and how to solve it. Some forums talk about this problem, but no solution is adapted to my case.

    I don't know much about command line compilation and compilation in general. I'm just doing a test out of curiosity.

    I am on Qt6

    Thanks in advance.

    Kent-DorfmanK Chris KawaC 2 Replies Last reply
    0
    • K Kev_

      Hi everyone,

      I'm doing a test. I have created an empty qmake project with Qt creator. I added a file main.cpp. A small code in main.cpp just displays a button. I want to use the created main.o file to build the obtained application in Qt Creator. For this, I make links between the main.o file and the libraries indicated in the Makefile.Debug file. I do it in command line and I use mingw_64 Version 12.2.0 (not the one in the Qt folder) to make the links.
      The command I use is the following:

      g++ main.o -LC:\Qt\6.4.0\mingw_64\lib -lQt6Widgets -lQt6Gui -lQt6Core -lQt6EntryPoint -o executabl_test
      

      I get the following error:

      undefined reference to `WinMain'
      

      the complete output is the following:

      C:/x86_64-12.2.0-release-posix-seh-rt_v10-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/x86_64-12.2.0-release-posix-seh-rt_v10-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
      collect2.exe: error: ld returned 1 exit status
      

      I also noticed that with or without the Qt6EntryPoint library I get the same error.
      I would like to know please what is the source of the problem and how to solve it. Some forums talk about this problem, but no solution is adapted to my case.

      I don't know much about command line compilation and compilation in general. I'm just doing a test out of curiosity.

      I am on Qt6

      Thanks in advance.

      Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by Kent-Dorfman
      #2

      @Kev_ said in How to solve the undefined reference to `WinMain' error for links made on command line?:

      get the following error:
      undefined reference to `WinMain'

      Well, what does this tell you? Perhaps your main.cpp doesn't declare WinMain, but perhaps a different entry point that is more POSIX common?

      Oh, and for what it's worth. Don't try to build Qt apps from command line manually (outside of makefiles). Therein lies madness.

      Christian EhrlicherC 1 Reply Last reply
      0
      • Kent-DorfmanK Kent-Dorfman

        @Kev_ said in How to solve the undefined reference to `WinMain' error for links made on command line?:

        get the following error:
        undefined reference to `WinMain'

        Well, what does this tell you? Perhaps your main.cpp doesn't declare WinMain, but perhaps a different entry point that is more POSIX common?

        Oh, and for what it's worth. Don't try to build Qt apps from command line manually (outside of makefiles). Therein lies madness.

        Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        I would guess some defines like QT_WIDGETS_LIB and QT_CORE_LIB and others. Also the subsystem must be correctly passed to the link, don't know how this is done for g++ though.
        Use qmake or cmake instead.

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

        1 Reply Last reply
        0
        • K Kev_

          Hi everyone,

          I'm doing a test. I have created an empty qmake project with Qt creator. I added a file main.cpp. A small code in main.cpp just displays a button. I want to use the created main.o file to build the obtained application in Qt Creator. For this, I make links between the main.o file and the libraries indicated in the Makefile.Debug file. I do it in command line and I use mingw_64 Version 12.2.0 (not the one in the Qt folder) to make the links.
          The command I use is the following:

          g++ main.o -LC:\Qt\6.4.0\mingw_64\lib -lQt6Widgets -lQt6Gui -lQt6Core -lQt6EntryPoint -o executabl_test
          

          I get the following error:

          undefined reference to `WinMain'
          

          the complete output is the following:

          C:/x86_64-12.2.0-release-posix-seh-rt_v10-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/x86_64-12.2.0-release-posix-seh-rt_v10-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
          collect2.exe: error: ld returned 1 exit status
          

          I also noticed that with or without the Qt6EntryPoint library I get the same error.
          I would like to know please what is the source of the problem and how to solve it. Some forums talk about this problem, but no solution is adapted to my case.

          I don't know much about command line compilation and compilation in general. I'm just doing a test out of curiosity.

          I am on Qt6

          Thanks in advance.

          Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Kev_ You are missing -lmingw32 in the link command. The order of the libraries is important due to how they interact, so make sure this is listed before -lQt6EntryPoint.

          Second thing is that you're trying to build a widgets app. By default your app will be linked using console subsystem, meaning your app will open a terminal window and then the UI window. To avoid that you should specify that you want a windows subsystem. This is done by specifying -Wl,-subsystem,windows in the command line.

          So the entire thing should look something like this:

          g++ main.o -Wl,-subsystem,windows -LC:\Qt\6.4.0\mingw_64\lib -lmingw32 -lQt6Widgets -lQt6Gui -lQt6Core -lQt6EntryPoint -o executabl_test
          
          K 1 Reply Last reply
          2
          • Chris KawaC Chris Kawa

            @Kev_ You are missing -lmingw32 in the link command. The order of the libraries is important due to how they interact, so make sure this is listed before -lQt6EntryPoint.

            Second thing is that you're trying to build a widgets app. By default your app will be linked using console subsystem, meaning your app will open a terminal window and then the UI window. To avoid that you should specify that you want a windows subsystem. This is done by specifying -Wl,-subsystem,windows in the command line.

            So the entire thing should look something like this:

            g++ main.o -Wl,-subsystem,windows -LC:\Qt\6.4.0\mingw_64\lib -lmingw32 -lQt6Widgets -lQt6Gui -lQt6Core -lQt6EntryPoint -o executabl_test
            
            K Offline
            K Offline
            Kev_
            wrote on last edited by
            #5

            @Chris-Kawa
            Hello,
            thank you very much for your help. I have no more linker problem. The executable is produced. Now I just have to solve the following problem:

            Application failed to start because no Qt platform plugin could be initialized
            

            I'm still trying to solve this, but if you have an idea, I would be grateful if you could share it with me.

            Thanks again for your precious help.

            Chris KawaC 1 Reply Last reply
            0
            • K Kev_ has marked this topic as solved on
            • K Kev_

              @Chris-Kawa
              Hello,
              thank you very much for your help. I have no more linker problem. The executable is produced. Now I just have to solve the following problem:

              Application failed to start because no Qt platform plugin could be initialized
              

              I'm still trying to solve this, but if you have an idea, I would be grateful if you could share it with me.

              Thanks again for your precious help.

              Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Kev_ As the message says you're missing the platform plugin. It's located in your Qt installation dir in the plugins\platforms dir. You'll also need a style plugin from plugins\styles.

              Qt comes with a tool windeployqt that copies all needed dependencies to your executable directory. Run it with your executable as a parameter and it will do all the work for you.

              1 Reply Last reply
              0

              • Login

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