0

I want to set /SUBSYSTEM:WINDOWS option to a executable,but there is a default option /subsystem:console in there,I try to override it, but it didn't work. Here is the log

cmd.exe /C "cd .&& F:\environment_application\CLion-2021.3.4.win\bin\cmake\win\bin\cmake.exe -E vs_link_exe --intdir=chapter5\CMakeFiles\meminfo.dir --rc="F:\Windows Kits\10\bin\10.0.22000.0\x64\rc.exe" --mt="F:\Windows Kits\10\bin\10.0.22000.0\x64\mt.exe" --manifests  -- F:\environment_application\visual_studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\link.exe /nologo chapter5\CMakeFiles\meminfo.dir\memInfo.cpp.obj  /out:chapter5\meminfo.exe /implib:chapter5\meminfo.lib /pdb:chapter5\meminfo.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console /subsystem:WINDOWS   kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK Pass 1: command "F:\environment_application\visual_studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\link.exe /nologo chapter5\CMakeFiles\meminfo.dir\memInfo.cpp.obj /out:chapter5\meminfo.exe /implib:chapter5\meminfo.lib /pdb:chapter5\meminfo.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console /subsystem:WINDOWS /SUBSYSTEM:WINDOWS kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:chapter5\CMakeFiles\meminfo.dir/intermediate.manifest chapter5\CMakeFiles\meminfo.dir/manifest.res" failed (exit code 1120) with the following output:
libcmtd.lib(exe_winmain.obj): error LNK2019: unresolved external symbol WinMain referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

notice the link options is

/version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console /subsystem:WINDOWS

The cmake code i used is here:

add_executable(meminfo memInfo.cpp memInfo.h)
target_compile_options(meminfo PUBLIC /MTd)
target_link_options(meminfo PUBLIC /SUBSYSTEM:WINDOWS)
set_target_properties(meminfo PROPERTIES
        LINK_FLAGS
        /subsystem:WINDOWS
        )

1 Answers1

0

Set the WIN32_EXECUTABLE to True.

set_target_properties(meminfo PROPERTIES WIN32_EXECUTABLE True)

You could also use the add_executable command to do this:

add_executable(meminfo WIN32 memInfo.cpp memInfo.h)
fabian
  • 80,457
  • 12
  • 86
  • 114