MinGW 编译的程序在 64 位 Windows 上崩溃 [英] MinGW compiled programs crash on 64 bit Windows

查看:19
本文介绍了MinGW 编译的程序在 64 位 Windows 上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在带有 Intel Core i7-3612QM 的 64 位 Windows 7 上安装了 32 位 MinGW 和 64 位 Eclipse CDT.当我编译并运行 hello world 时,字符串会打印出来,但程序随后会得到一个 SIGILL.

I have 32bit MinGW and 64 bit Eclipse CDT installed on 64 bit Windows 7 with an Intel Core i7-3612QM. When I compile and run hello world, the string prints, but the program gets a SIGILL afterward.

来源:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello World!" << endl;
    return 0;
}

堆栈跟踪:

hello.exe [C/C++ Application]   
    hello.exe [5532]    
        Thread [1] 0 (Suspended : Signal : SIGILL:Illegal instruction)  
            libstdc++-6!_ZSt4cout() at 0x6fccc3c0   
            libstdc++-6!_ZNSolsEPFRSoS_E() at 0x6fc8908c    
            _fu0___ZSt4cout() at hello.cpp:5 0x4013be   
    gdb 

添加 cin 会导致段错误:

Adding cin causes a segfault:

来源:

#include <iostream>
#include <string>

using namespace std;

int main() {
    string name;
    cout << "Please type your name: ";
    cin >> name;
    cout << "Hello " << name << endl;
    return 0;
}

详细的编译器输出:

C:UsersSean	emp>g++ -v main.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.2/configure --enable-languages=c,c++,ada,fortran,obj
c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo
mp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-r
untime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.2 (GCC)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=i386' '-march=i386'
 c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/cc1plus.exe -quiet -v -iprefix c:min
gwin../lib/gcc/mingw32/4.6.2/ main.cpp -quiet -dumpbase main.cpp -mtune=i386
-march=i386 -auxbase main -version -o C:UsersSeanAppDataLocalTempccSVBzeY.
s
GNU C++ (GCC) version 4.6.2 (mingw32)
        compiled by GNU C version 4.6.2, GMP version 5.0.1, MPFR version 2.4.1,
MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "c:mingwin../lib/gcc/mingw32/4.6.2/../../../.
./mingw32/include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de/c++"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de/c++/mingw32"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de/c++/backward"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de"
ignoring duplicate directory "/mingw/lib/gcc/mingw32/4.6.2/../../../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../include"
ignoring duplicate directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/inclu
de-fixed"
ignoring nonexistent directory "c:/mingw/lib/gcc/../../lib/gcc/mingw32/4.6.2/../
../../../mingw32/include"
ignoring duplicate directory "/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 c:mingwin../lib/gcc/mingw32/4.6.2/include/c++
 c:mingwin../lib/gcc/mingw32/4.6.2/include/c++/mingw32
 c:mingwin../lib/gcc/mingw32/4.6.2/include/c++/backward
 c:mingwin../lib/gcc/mingw32/4.6.2/include
 c:mingwin../lib/gcc/mingw32/4.6.2/../../../../include
 c:mingwin../lib/gcc/mingw32/4.6.2/include-fixed
End of search list.
GNU C++ (GCC) version 4.6.2 (mingw32)
        compiled by GNU C version 4.6.2, GMP version 5.0.1, MPFR version 2.4.1,
MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: f7eb4168c2cf10318cc29da8d23b7f3c
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=i386' '-march=i386'
 c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/as.exe -o C:User
sSeanAppDataLocalTempccb0vTGl.o C:UsersSeanAppDataLocalTempccSVBzeY.s

COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/;c:/mingw/bin/../libexec
/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.6.2/;c:/mingw/bin/../lib/gcc/;c:/
mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/lib/;c:/mingw/bin/../lib/
gcc/mingw32/4.6.2/../../../;/mingw/lib/
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=i386' '-march=i386'
 c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/collect2.exe -Bdynamic -u ___register
_frame_info -u ___deregister_frame_info c:/mingw/bin/../lib/gcc/mingw32/4.6.2/..
/../../crt2.o c:/mingw/bin/../lib/gcc/mingw32/4.6.2/crtbegin.o -Lc:/mingw/bin/..
/lib/gcc/mingw32/4.6.2 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw
32/4.6.2/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../.
. -L/mingw/lib C:UsersSeanAppDataLocalTempccb0vTGl.o -lstdc++ -lmingw32 -l
gcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel
32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc
/mingw32/4.6.2/crtend.o

堆栈跟踪:

hello.exe [C/C++ Application]   
    hello.exe [9092]    
        Thread [1] 0 (Suspended : Signal : SIGSEGV:Segmentation fault)  
            libstdc++-6!_ZNSs12_Alloc_hiderC1EPcRKSaIcE() at 0x6fc89542 
            libstdc++-6!_ZNSsC1Ev() at 0x6fc8c38b   
            main() at hello.cpp:7 0x4013a7  
    gdb 

使用 32 位 code::blocks 或从命令行手动编译时也会出现问题.

The problems also occur using 32 bit code::blocks or when compiled manually from the command line.

我该如何解决这个问题?

How can I fix this?

推荐答案

当我试图在另一台没有安装 MinGW 的计算机上运行 EXE 时,它抱怨:

When I tried to run the EXE on another computer that didn't have MinGW intalled, it complained:

程序无法启动,因为您缺少 libgcc_s_dw2-1.dll计算机.尝试重新安装程序以解决此问题.

The program can't start because libgcc_s_dw2-1.dll is missing from you computer. Try reinstalling the program to fix this problem.

谷歌搜索该错误使我想到了 SO 问题 程序无法启动,因为缺少libgcc_s_dw2-1.dll

Googling that error led me to the SO question The program can't start because libgcc_s_dw2-1.dll is missing

来自答案:

libgcc_s_dw2-1.dll 应该在编译器的 bin 目录中.您可以将此目录添加到 PATH 环境变量中运行时链接,或者您可以通过添加来避免该问题-static-libgcc -static-libstdc++"到你的编译器标志.

The libgcc_s_dw2-1.dll should be in the compiler's bin directory. You can add this directory to your PATH environment variable for runtime linking, or you can avoid the problem by adding "-static-libgcc -static-libstdc++" to your compiler flags.

所以我添加了标志,结果程序在两个系统上都能正常运行.我不确定为什么需要这些标志才能在我的开发系统上正常工作,因为 MinGW bin 目录位于 PATH 中.任何人都可以提供解释吗?我应该创建一个单独的问题吗?

So I added the flags, and the resulting program ran normally on both systems. I'm not sure why these flags were required for it to work properly on my dev system, because the MinGW bin directory is in the PATH. Can anyone provide an explinantion? Should I create a seperate question?

这篇关于MinGW 编译的程序在 64 位 Windows 上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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