问题
I am trying to compile a program that was provided to me. The program tests the run time of the algorithm quicksort when provided different values. I need to increase the size of the stack to run really large numbers.
I read to use the following command: g++ -Wl,--stack,<size>
where size is the number to increase the stack.
However, this isn't working for me. In command prompt when I typed exactly the following:
g++ -Wl,--stack,1000000000
and then hit enter, I get the following message:
C:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to 'WinMain@16' collect2.exe: error: ld returned 1 exit status
I am not allowed to change the code so my only option is to increase the stack size in command prompt and then run my code.
I don't know what I am doing wrong. Am I typing in the command incorrectly?
How do I increase the stack size in command prompt for a c++ program using MinGW compiler? I am using Windows 10, if that information is helpful.
回答1:
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)
来源:https://stackoverflow.com/questions/54821412/how-to-increase-stack-size-when-compiling-a-c-program-using-mingw-compiler