Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-80097

qmake: linker error about WinMain@16

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.9.4, 5.13.1
    • Build tools: qmake
    • None
    • Windows 8.1 64bit, Qt Creator 4.10.1
      Qt 5.9.4 msvc 2015 32bit
      Qt 5.13.1 msvc 2017 64bit
      Qt 5.13.1 MinGW 7.3 32bit
    • Windows

    Description

      Linker throws error when trying to compile a simple program from .pro file that uses Catch library:

      #define CATCH_CONFIG_MAIN
      #include "catch.hpp"
      
      TEST_CASE("test", "[test]")
      {
      	REQUIRE(1==1);
      }
      
      TEMPLATE = app
      
      CONFIG -= qt
      CONFIG += cmdline c++11
      
      HEADERS = catch.hpp
      SOURCES = test.cpp
      

      This happens when using kits Qt 5.9.4 msvc 2015 32bit and Qt 5.13.1 MinGW 7.3 32bit, but doesn't happen with Qt 5.13.1 msvc 2017 64bit kit.

      Invoking compiler directly on the command line (cl / g++) succeeds in all the above cases. This leads me to think that qmake is guilty, maybe some mkspecs settings?

      I also tried to use qbs instead of qmake: both msvc builds succeeded, but for MinGW I had to add DO_NOT_USE_WMAIN define that forces Catch to create main instead of wmain, see here. The same define had no effect on qmake.

      Someone has already faced this issue: https://github.com/catchorg/Catch2/issues/1287, but the workaround from there still doesn't solve error in msvc 2015 with qmake.

      Actual linker errors:

      MSVC 2015 (for w/e reason it uses subsystem windows, I tried to force console through QMAKE_LFLAGS, but that didn't help either)

      link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:debug\test.exe @C:\Users\Andrey\AppData\Local\Temp\test.exe.9116.15.jom
      MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
      debug\test.exe : fatal error LNK1120: 1 unresolved externals

      MinGW

      g++ -Wl,-subsystem,console -mthreads -o debug\test.exe debug/test.o  
      C:/Qt/Tools/mingw730_32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x39): undefined reference to `WinMain@16'
      collect2.exe: error: ld returned 1 exit status

      Just in case linker output from MSVC 2017 (this one was done by invoking qmake without options on command line and then running nmake):

      link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /SUBSYSTEM:CONSOLE "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:release\test.exe @C:\Users\Andrey\AppData\Local\Temp\nmBD97.tmp

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtbuildsystem Qt Build System Team
            kambala Andrey Filipenkov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes