Windows clang not honoring WIN32_EXECUTABLE flag
Using clang
, not clang-cl
, on Windows doesn't set CMAKE_CREATE_WIN32_EXE
. This results in no explicit subsystem being set during linking and causes lld-link
to choose automatically. lld-link
makes its choice based on the presence of either a main
or WinMain
function, which is fine most of the time, but defaults to /subsystem:console
when both are present such as when linking to qtmain.lib
.
I fixed this locally by copying the definitions from Windows-MSVC.cmake
to Windows-Clang.cmake
and prefixing them with -Xlinker
, but I'm not sure if that is the desired solution or not.
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsCE")
set(CMAKE_CREATE_WIN32_EXE "-Xlinker /entry:WinMainCRTStartup")
set(CMAKE_CREATE_CONSOLE_EXE "-Xlinker /entry:mainACRTStartup")
set(_PLATFORM_LINK_FLAGS " -Xlinker /subsystem:windowsce")
else()
set(CMAKE_CREATE_WIN32_EXE "-Xlinker /subsystem:windows")
set(CMAKE_CREATE_CONSOLE_EXE "-Xlinker /subsystem:console")
set(_PLATFORM_LINK_FLAGS "")
endif()