devil0150
devil0150

Reputation: 1469

Setting linker subsystem with CMake and clang++ in windows

I'm trying to make a windowed application with SDL in windows, using ninja to build. When I try to build, I get the error:

lld-link: error: subsystem must be defined

It seems I need to set the /SUBSYSTEM:WINDOWS linker flag for it to work. How can I set that in CMake?

I tried using the WIN32 flag mentioned in add_executable, but the clang command doesn't change when I try to build again, and the error still happens.

I looked at this question too, even though it seems to refer to a different issue, but it didn't help. I also tried the other answer in this question, adding

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

but it just throws no such file or directory: '/SUBSYSTEM:WINDOWS'.

Upvotes: 2

Views: 3746

Answers (1)

user2807083
user2807083

Reputation: 2982

You can try to use

target_link_options(your_target_name PRIVATE "/SUBSYSTEM:WINDOWS")

See cmake documentation: https://cmake.org/cmake/help/git-stage/command/target_link_options.html

Upvotes: 2

Related Questions