Increase Stack Size When Compiling with Mingw

Increase stack size when compiling with mingw?

Use

gcc -Wl,--stack,N

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

How to increase stack size when compiling a C++ program using MinGW compiler

In order to change the size of the stack to run a C++ program that may cause a stack overflow, use the following command.

g++ -Wl,--stack,16777216 -o file.exe file.cpp

This increases the stack size to 16MiB, if you need it to be bigger then increase the value from 16777216 bytes to whatever value you need.

Do be sure to replace file.exe and file.cpp with the corresponding names of the file and executable that you are running.

Also note that in the command its -Wl (lower case L)

How to deal with the small stack size in MinGW?

You really should avoid using the stack for large things.

It's also a security risk as stack overflows wan be abused by hackers (e.g. to try to attempt running arbitrary code).

Better is to use the heap, you can do this by replacing

double Ar2D[arraySize][arraySize];

with

double** Ar2D = (double**)malloc(arraySize * arraySize * sizeof(double));

and of course don't forget to free(Ar2D);

Increase stack size in c++

I have solved problem, It should work in all IDEs I think, but it definitely works in Visual Studio. PROJECT->Properties->Configuration Properties->Linker->System->Stack Reserve Size=4194304 . This makes stack size 4 MB.



Related Topics



Leave a reply



Submit