CMake更改堆栈大小 [英] Cmake change stack size
问题描述
是否可以通过 Cmake 更改堆栈大小?
我只找到了一个论坛主题提到CMAKE_CXX_STACK_SIZE
,但是我找不到此命令的文档.理想情况下,该命令应同时适用于 Visual Studio C ++ 和 gcc .
Is there a way to change stack size from the Cmake ?
I only found one forum thread mentioning CMAKE_CXX_STACK_SIZE
but I couldn't find the documentation for this command. Ideally the command should work for both Visual Studio C++ and gcc.
推荐答案
目前我没有VS,但是以下三个CMake命令在MinGW/GCC上都对我有用(用输入的内容替换<target>
)进入add_executable()
):
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")
请注意,根据 CMake文档,每个文档都应添加链接器标志,而不是替换任何已设置的标志.
Note that according to the CMake documentation, each of these should just add linker flags, not replace any that are already set.
在VS中,您似乎应该将-Wl,--stack,
替换为/STACK:
(在下文中进行更多介绍),并使用if/else为每个编译器使用不同的命令.
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.
关于CMAKE_CXX_STACK_SIZE
,此线程,值得一读,说命令是
Regarding CMAKE_CXX_STACK_SIZE
, this thread, which is worth a read, says the command is
出于历史原因,在VS生成器的实现中使用并不是要用作设置堆栈大小的一流方法.相反,只需使用
target_link_libraries
或LINK_FLAGS
target属性或在CMAKE_EXE_LINKER_FLAGS
...
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 usingtarget_link_libraries
, or theLINK_FLAGS
target property, or inCMAKE_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")
这篇关于CMake更改堆栈大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!