应用程序分段错误,仅在使用 MinGW 在 Windows 上编译时

2022-01-12 00:00:00 windows gcc segmentation-fault mingw c++

我正在尝试在 Windows 上编译 我的一个游戏,但不幸的是,无论如何,每次运行程序时都会遇到此分段错误.

I'm trying to compile one of my games on Windows, but unfortunately, no matter what, I'm getting this segmentation fault every time I run the program.

编译成功,没有任何警告.

Compilation is successful, and without any warning.

程序收到信号SIGSEGV,分段错误.

Program received signal SIGSEGV, Segmentation fault.

__chkstk_ms () at ../../../../../src/gcc-4.8.1/libgcc/config/i386/cygwin.S:172

__chkstk_ms () at ../../../../../src/gcc-4.8.1/libgcc/config/i386/cygwin.S:172

172 ../../../../../src/gcc-4.8.1/libgcc/config/i386/cygwin.S:没有这样的文件或目录.

172 ../../../../../src/gcc-4.8.1/libgcc/config/i386/cygwin.S: No such file or directory.

我试过了:

  • 在 Windows x86 机器上编译
  • 在 Windows x64 机器上编译
  • nuwen.net 的 MinGW 发行版
  • TDM MinGW 4.8.1 SJLJ
  • MinGW 构建 x86 SJLJ
  • MinGW 构建 x64 SJLJ
  • MinGW 构建 x86 DW2

我已经多次从源代码构建所有依赖项,尝试静态和动态链接.

I've built all dependencies from source multiple times, tried linking both statically and dynamically.

调试也无济于事 - GDB 在输入 main() 时就给我该错误消息.我使用了 -g3-O0 标志.

Debugging doesn't help either - GDB gives me that error message just upon entering main(). I've used -g3 and -O0 flags.

我怎样才能知道发生了什么?

How can I figure out what's happening?

推荐答案

在 Windows 上,默认堆栈大小小于 Linux.__chkstk_ms 似乎是一个在堆栈溢出时崩溃的函数.

On Windows, the default stack size is smaller than Linux. __chkstk_ms appears to be a function that crashes if you overflow your stack.

您可能会尝试找出您在代码中的哪个位置创建了巨大的堆栈变量或进行了非常深的递归,然后修复它.

You may try to figure out where in your code you are creating huge stack variables or doing very deep recursion, and fix that.

或者,您可以添加一个编译标志来增加堆栈大小.请参阅 http://trac.sagemath.org/ticket/13960.

Alternately, you may be able to add a compile flag to increase the stack size. See http://trac.sagemath.org/ticket/13960.

相关文章