tags:

views:

242

answers:

3

Hi, 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

+4  A: 

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

moonshadow
Um, the heap uses address space too...
Andy J Buchanan
@Andy: but its size doesn't default to a fixed 2Mb and he doesn't have to ask for 256Mb of it up front in order to get his application to fit; the C library is pretty good at managing large allocations for him.
moonshadow
+1  A: 

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
Walt W
Hi!I tried these options with the IDE DEV-C++ (from bloodshed) but I still get stack overflow, any hints?
Werner
A: 

it works now, thanks!

Werner