在OS X上使用Clang编译时,如何增加堆栈大小? [英] How do I increase the stack size when compiling with Clang on OS X?

查看:241
本文介绍了在OS X上使用Clang编译时,如何增加堆栈大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Can I specify the stack size with clang++? I can't find any compiler options that would allow me to do so. I'm using OS X.

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

Note: This question specifically refers to Clang, not the GCC compiler.

推荐答案

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

The linker, rather than the compiler, is responsible for setting the stack size of the main thread. The man page for ld contains the following:

-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堆栈,您可以执行以下操作:

For instance, to specify a 16MB stack you could do the following:

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

请注意传递给cc的参数上的-Wl,前缀,以将其传递给链接器.

Note the -Wl, prefix on the arguments passed to cc to have it pass them on to the linker.

这篇关于在OS X上使用Clang编译时,如何增加堆栈大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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