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. Undefined reference to WinMain@16

Undefined reference to WinMain@16

Scheduled Pinned Locked Moved General and Desktop
9 Posts 6 Posters 25.8k 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.
  • L Offline
    L Offline
    lolopolosko
    wrote on last edited by
    #1

    Hi!
    I am build Qt on Windows, and install QtCreator.
    If I create new project -> C++ Library and compile this project, I see this error @undefined reference to WinMain@16@

    Build output
    @C:/Qt/MinGW/bin/mingw32-make -f Makefile.Release
    mingw32-make[1]: Entering directory C:/Users/Ruslan/Documents/Qt/untitled' g++ -c -O2 -Wall -Wextra -fno-exceptions -fno-rtti -DUNICODE -DQT_LARGEFILE_SUPPORT -DUNTITLED_LIBRARY -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NO_DYNAMIC_CAST -I"c:\Qt\4.8.3\include\QtCore" -I"c:\Qt\4.8.3\include" -I"c:\Qt\4.8.3\include\ActiveQt" -I"release" -I"c:\Qt\4.8.3\mkspecs\win32-g++" -o release\untitled.o untitled.cpp g++ -Wl,-s -o release\libuntitled.a release/untitled.o -L".\lib" -L"c:\Qt\4.8.3\lib" -lQtCore4 mingw32-make[1]: Leaving directory C:/Users/Ruslan/Documents/Qt/untitled'
    c:/qt/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a(main.o): In function main': C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to WinMain@16'
    collect2: ld returned 1 exit status
    mingw32-make[1]: *** [release\libuntitled.a] Error 1
    mingw32-make: *** [release] Error 2@

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      The entry point for Windows GUI applications is WinMain(), not main().

      Obviously your application doesn't implement a proper WinMain() function, as described here:
      http://msdn.microsoft.com/en-us/library/windows/desktop/ms633559(v=vs.85).aspx

      Link your application against "qtmain.lib", if you want to use a classical main() method.


      But be aware that then your main() method will be called by a "dummy" WinMain() function implemented in "qtmain.lib", it will NOT be called by the C-Runtime directly. This also means that Qt's code will create the "argc" and "argv" arguments for your main() method itself. You wouldn't have to care about that, if Qt's command-line parser/tokenizer didn't have a rather annoying bug that still remains unfixed, as nobody seems to care...

      See here for details:
      https://bugreports.qt-project.org/browse/QTBUG-26303

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbzhang800
        wrote on last edited by
        #3

        Hi MuldeR, what he created is a library instead of application. so main or WinMain is not needed.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lolopolosko
          wrote on last edited by
          #4

          Yes, this is not application
          It is library.
          I recompiled Qt and reinstall Mingw. But this problem not solved.

          Now I install msvc 2010 and this works

          But I want use Mingw, not MSVC

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MuldeR
            wrote on last edited by
            #5

            Hmm, if he indeed is compiling a DLL and the linker is complaining about a missing reference to "WinMain@16", it seems the wrong C-Runtime (CRT) is being linked in. The DLL CRT shouldn't have a reference to "WinMain@16" at all. It should have a reference to "DllMain()":http://tinyurl.com/cqwzvxq Might be a configuration error (or a screwed up MinGW).

            My OpenSource software at: http://muldersoft.com/

            Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

            Go visit the coop: http://youtu.be/Jay...

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kalleboll
              wrote on last edited by
              #6

              Yes it seems that it doesn't understand that it in fact should be a library. Is your project file properly setup? It might help if we can see it. For example does it have a template for a lib etc?
              @TEMPLATE = lib@

              Also it might help if we could look at the generated Makefile for the project if you can share that?

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lolopolosko
                wrote on last edited by
                #7

                I solved this problem
                I am uninstall Mingw 4.6, and download Mingw version 4.4
                Then rebuild Qt libs and this work fine

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kwalle
                  wrote on last edited by
                  #8

                  just add

                  @CONFIG += shared@

                  to your .pro-file!

                  qmake seems to be confused if neither -shared nor -static build is specified ...

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    vaychick
                    wrote on last edited by
                    #9

                    Thanks kwalle

                    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