使用MinGW编译器编译C ++程序时如何增加堆栈大小 [英] How to increase stack size when compiling a C++ program using MinGW compiler

查看:144
本文介绍了使用MinGW编译器编译C ++程序时如何增加堆栈大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译提供给我的程序.当提供不同的值时,程序将测试算法快速排序的运行时间.我需要增加堆栈的大小才能运行很大的数字.

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.

我阅读使用以下命令: g ++ -Wl,-stack,< size>

I read to use the following command: g++ -Wl,--stack,<size>

其中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

然后按Enter,我得到以下消息:

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):未定义对"WinMain @ 16" collect2.exe的引用:错误:ld返回1退出状态

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?

如何使用MinGW编译器在c ++程序的命令提示符下增加堆栈大小?如果该信息有帮助,我正在使用Windows 10.

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.

推荐答案

为了更改堆栈的大小以运行可能导致堆栈溢出的C ++程序,请使用以下命令.

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

这会将堆栈大小增加到16MiB,如果需要更大的大小,则将值从 16777216 字节增加到所需的任何值.

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.

请确保将 file.exe file.cpp 替换为您正在运行的文件和可执行文件的相应名称.

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

还要注意,在命令中其 -Wl (小写L)

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

这篇关于使用MinGW编译器编译C ++程序时如何增加堆栈大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆