【问题标题】:How do I increase the stack size when compiling with Clang on OS X?在 OS X 上使用 Clang 编译时如何增加堆栈大小?
【发布时间】:2013-09-25 09:45:22
【问题描述】:

我可以用 clang++ 指定堆栈大小吗?我找不到任何允许我这样做的编译器选项。我正在使用 OS X。

注意:这个问题专门针对 Clang,而不是 GCC 编译器。

【问题讨论】:

标签: macos ld compiler-options stack-size


【解决方案1】:

链接器而不是编译器负责设置主线程的堆栈大小。 ld 的手册页包含以下内容:

-stack_size size
    Specifies the maximum stack size for the main thread in a program. Without this
    option a program has a 8MB stack. The argument size is a hexadecimal number with
    an optional leading 0x. The size should be an even multiple of 4KB, that is the
    last three hexadecimal digits should be zero.

例如,要指定一个 16MB 的堆栈,您可以执行以下操作:

mrowe@apollo:~$ cc -Wl,-stack_size -Wl,0x1000000 -o test test.m
mrowe@apollo:~$ otool -lV test | grep stack
 stacksize 16777216

注意传递给cc 的参数上的-Wl, 前缀,以便将它们传递给链接器。

【讨论】:

    猜你喜欢
    • 2012-04-30
    • 2011-04-03
    • 2011-07-05
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 2014-03-21
    • 1970-01-01
    • 2015-11-22
    相关资源
    最近更新 更多