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:

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

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:

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

Have a question⁉ Contact me.