简体   繁体   中英

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:

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

Under Linux, I just tried 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

-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. 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

If that fails on its own, then this other page suggests to also add:

-fstack-check

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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