Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt project in Visual Studio 2015: "unresolved external symbol wWinMain"

The whole error output being:

LNK2019 unresolved external symbol wWinMain referenced in function "int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ)  kachna-tracker  C:\dev\kachna-tracker\MSVCRT.lib(exe_wwinmain.obj)

This is a project imported from Qt Creator, and this error only occurs when I try to build the Release version, Debug version runs just fine. As far as I can tell, besides using the debug versions of the libraries (e.g. qtmain.lib/qtmaind.lib), there is no difference in the linker configuration between the Debug and Release configurations.

I've found that this error can be fixed by setting the SubSystem to /SUBSYSTEM:CONSOLE instead of /SUBSYSTEM:WINDOWS, and this indeed does fix the issue, but as I am building a GUI application, a permanently open console window is quite unsightly, and also probably only fixes the symptom rather than the cause.

How to fix this error?

like image 950
Tomáš M. Avatar asked Sep 25 '16 16:09

Tomáš M.


1 Answers

TL;DR

Either:

  • Disable Unicode in Release
  • Or add the /entry:mainCRTStartup linker flag in Release

The qtmain library provides a wrapper around the WinMain function on Windows, to allow you to define a cross-platform main() function. But for now, the wWinMain function (the unicode version of the WinMain entry point) is not supported by the qtmain library.

Maybe the difference between your Debug and Release builds is that you compile with Unicode enabled in Release and not in Debug.

If you want to compile with Unicode enabled, you should not link with the qtmain library, and you should define wWinMain instead of plain old main.

Alternatively, you can add the /entry:mainCRTStartup linker flag in order to keep your beautiful and standard main function. See this link for more information, and this awesome answer for detailed information about entry points.

like image 83
fkorsa Avatar answered Nov 19 '22 09:11

fkorsa