在OS X上使用Clang进行编译时如何增加堆栈大小?

时间:2013-09-20 05:25:21

标签: macos ld compiler-options stack-size

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

注意:这个问题具体是指Clang,而不是GCC编译器。

1 个答案:

答案 0 :(得分:17)

链接器而不是编译器负责设置主线程的堆栈大小。 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

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

相关问题