gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 17:01:50 29 4
gpt4 key购买 nike

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

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

最佳答案

链接器而不是编译器负责设置主线程的堆栈大小。 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, 前缀,以便将其传递给链接器。

关于macos - 在 OS X 上使用 Clang 编译时如何增加堆栈大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36813981/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com