Use wmain in CMake for Windows

Problem

Windows has special entry point wmain which is fully UNICODE compliant but CMake won’t recognise it out of the box:

1int wmain(int argc, wchar_t* argv[], wchar_t* envp[])
2{
3	return 0;
4}

might get an error like LNK2019… unresolved external symbol main referenced in function “int __cdecl invoke_main(void)” (?invoke_main@@YAHXZ) …MSVCRTD.lib(exe_main.obj).

Solution

Explicitly set program entry point in CMake:

1set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:wmainCRTStartup")

Have feedback or questions? Feel free to email me.