5

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.

4
  • Does it work for smaller values of stack size? Commented Feb 22, 2019 at 6:42
  • Yes it works for small values like 10,000. If I try 1,000,000 it simply doesn't work. I don't get an error message or anything, the program just ends. Commented Feb 22, 2019 at 6:57
  • All I can suggest is that you keep halving the stack size until you find a value that produces a working exe and see if that runs without running out of stack space. Commented Feb 22, 2019 at 17:10
  • I was able to figure it out. I posted the answer below in case someone else has the same question. Commented Feb 23, 2019 at 3:51

2 Answers 2

5

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)

Sign up to request clarification or add additional context in comments.

Comments

1
g++ -Wl,--stack,1000000000 -o main.exe main.cpp

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.