Cmake 更改堆栈大小 [英] Cmake change stack size

查看:58
本文介绍了Cmake 更改堆栈大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从 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")

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

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_librariesLINK_FLAGS 目标属性或在 CMAKE_EXE_LINKER_FLAGS<中将 /STACK:... 作为链接器标志传递/代码>...

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")

这篇关于Cmake 更改堆栈大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆