Cmake change stack size

◇◆丶佛笑我妖孽 提交于 2019-12-01 11:02:11

I don't have VS at the moment, but the following three CMake commands all work for me on MinGW/GCC (replace <target> with what you entered into add_executable()):

target_link_libraries(<target> PRIVATE "-Wl,--stack,10000000")

OR

set_target_properties(<target> PROPERTIES LINK_FLAGS -Wl,--stack,10000000)

OR

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,10000000")

Note that according to the CMake documentation, each of these should just add linker flags, not replace any that are already set.

In VS, it looks like you should replace -Wl,--stack, with /STACK: (more on this below) and use an if/else to have different commands for each compiler.

Regarding CMAKE_CXX_STACK_SIZE, this thread, which is worth a read, says the command is

in the implementation of the VS generator for historical reasons but is not intended as a first-class way to set the stack size. Instead just pass /STACK:... as a linker flag using target_link_libraries, or the LINK_FLAGS target property, or in CMAKE_EXE_LINKER_FLAGS...

Such a command can actually be seen on the page linked in your post (not sure if you saw it) as well as in this one:

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