PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, June 26, 2022

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

 June 26, 2022     c++, compiler-errors, mingw, stack-overflow     No comments   

Issue

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.


Solution

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)



Answered By - LiveToLearn
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing