简体   繁体   English

使用GNU G ++的Windows中的堆栈限制的解决方法

[英]Workaround for stack limit in windows with gnu g++

I have built and compiled a command line program with GNU g++ which "overflows" the stack for a number of reasons, mainly deep inheritance, lots of objects created, etc. So I followed this workaround on Mac OS X to solve the problem when linking: 我已经用GNU g ++构建并编译了一个命令行程序,该程序由于多种原因会“溢出”堆栈,主要是深层继承,创建的许多对象等。因此,我在Mac OS X上遵循了此变通办法来解决链接时的问题。 :

-Wl,-stack_size,0x10000000,-stack_addr,0xc0000000

Under Linux, I just tried ulimit -s unlimited ; 在Linux下,我只是尝试了ulimit -s unlimited ; running the program in this way does not give a segmentation fault any more 以这种方式运行程序不会再出现分段错误

But when trying to compile it on Windows with GNU g++, the compiler does not recognize 但是,当尝试在使用GNU g ++的Windows上进行编译时,编译器无法识别

-Wl,-stack_size,0x10000000,-stack_addr,0xc0000000

What other option would you use as a workaround for the problem? 您还可以使用其他什么方法解决该问题?

Thanks in advance 提前致谢

-Wl,--stack, somelargesize looks like what you're after. -Wl--堆栈,看起来像是您想要的。 However, I'd strongly recommend refactoring your code to make use of the heap for large allocations instead. 但是,我强烈建议您重构您的代码,以利用堆进行较大的分配。 Address space is a finite resource and your "workaround" asks for quite a large chunk of it. 地址空间是有限的资源,您的“解决方法”需要很大一部分资源。

This page suggests that you might want to try the following command line option (search for -fno-stack-limit): 该页面建议您可能需要尝试以下命令行选项(搜索-fno-stack-limit):

-fno-stack-limit

If that fails on its own, then this other page suggests to also add: 如果该操作本身失败,那么另一页建议还添加:

-fstack-check

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM