Correctly set Visual Studio linker flag /SUBSYSTEM in CMAKE

不问归期 提交于 2021-01-21 12:36:12

问题


I am trying to set up an old project using cmake and I would like to keep all flags the same as before. The old project generator has the linker flag /SUBSYSTEM with minimum subystem version number 5.01 set like this:

/SUBSYSTEM:WINDOWS,"5.01"

I tried the same in cmake by adding this:

set_target_properties(mytarget PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS,\"5.01\"")

However the result is wrong. Cmake seems to remove the (escaped) double quotes and places the linker flag to "Addition Options" in the Visual Studio project: /SUBSYSTEM:WINDOWS,5.01

This way the subsystem flag is not recognized and set to CONSOLE.

I tried several combinations how to add the min version ,"5.01" to the subsystem flag but without success.

Is there any other way to add the minimum subsystem version number to the /SUBSYSTEM flag?


回答1:


You can simply use the [WIN32] flag in the add_executable function :

add_executable(${PROJECT_NAME} WIN32 main.cpp)



回答2:


Long time to answer but I have found a solution:

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


来源:https://stackoverflow.com/questions/33873735/correctly-set-visual-studio-linker-flag-subsystem-in-cmake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!