Search code examples
c++stack-overflowstackmingwcallstack

Increase stack size when compiling with mingw?


I'm writing a recursive flood-fill algorithm to find connected components in an image, my code compiles and runs well with MSVC 2008 compiler; but the mingw-compiled binary crashed at runtime.

After I converted the algorithm to non-recursive with std::stack, everything goes well.

But what if I must use recursive algorithm in some case, and mingw cannot handle it?

How can I increased stack size of a binary, is there any compilation options?

Thanks


Solution

  • Use

    gcc -Wl,--stack,N
    

    where N is stack size. E.g. gcc -Wl,--stack,4194304