1

I am building a Windows application based on Qt using VisualStudio 2017 Professional (15.9.35) and the Qt VS Tools add-on. The project compiled fine up to a certain point, now the linker gives the error:

10>MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

The target Qt version is Qt-5.12.10-msvc2017-32 (my application is 32-bit). My application defines main(), I expect WinMain to be defined by Qt which in turn will call my main() (as stated here, it worked at earlier stages of the development)

What I've checked (in the project for the application, and also in the dependency libraries project that are in the same VS solution):

  • Qt modules: core;gui;testlib;widgets
  • Subsystem: Windows (/SUBSYSTEM:WINDOWS)
  • Character Set: blank (it's not either "Not set", it's set that way by the Qt VS Tools add-on when first creating a project)
  • Treat wchar_t as built-in type: Yes (/Zc:wchar_t)
  • Not an answer, but I also tried moving a qt (built with qmake) to VS for a bit. Took a long while to get it working, and then it broke often whenever I wanted to use another qt feature. After adding and having issues with qt resources I reluctantly switched back to Qt Creator. Might be a better experience if you're using cmake though. – benk May 13 '21 at 09:59
  • Take a look at https://bugreports.qt.io/browse/QTBUG-93671 - maybe it fits to your problem. – chehrlic May 13 '21 at 14:07
  • You need to link to the qtmain library. [https://doc.qt.io/qt-5/qtmain.html](https://doc.qt.io/qt-5/qtmain.html) not sure why this is not happening. I use CMake to generate my Qt + Visual Studio projects since 2008. – drescherjm May 13 '21 at 14:55

1 Answers1

0

I got the same error in test builds using GitHub Actions for Windows and Qt 6, but at the same time the program built for Windows and Qt 5 without problems. Building for Linux and macOS was successful in any configuration. This was doubly strange because in another project using Qt the build completed successfully in any configuration.

I removed the
CONFIG += qt
lines in the qmake scripts and the build succeeded for Windows and Qt 6.

u-235
  • 361
  • 1
  • 6