用MinGW编译的C ++ HelloWorld程序会因“非法参数"而崩溃. [英] C++ HelloWorld program compiled with MinGW crashes with "Illegal Argument"

查看:64
本文介绍了用MinGW编译的C ++ HelloWorld程序会因“非法参数"而崩溃.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为是该学习C ++的时候了,经过3个多小时的努力,尝试使编译器正常工作之后,我终于创建了一个正常工作的程序.但是,当我尝试通过剪切和粘贴在Eclipse中重构项目时,它似乎自发地崩溃了.该程序只是崩溃了,Windows弹出了可怕的对话框"HelloWorld.exe已停止工作".一点调试显示,"cout"被认为是非法论点.我对该问题进行了更多研究,现在我怀疑它与显然是32位的编译器有关,因为我使用的是64位系统.该可执行文件在Eclipse中列为"HelloWorld.exe-[x86/le]".(减去句点.)我的完整程序如下:

I decided it was time that I learned C++, and after struggling for 3+ hours trying to get the compiler to work, I finally created a working program. However, it seemingly spontaneously broke when I tried to refactor the project in Eclipse by cutting and pasting it. The program simply crashes, and Windows brings up the dreaded dialogue "HelloWorld.exe has stopped working." A bit of debugging revealed that "cout" was considered an illegal argument. I looked some more into the issue, and I'm now suspicious that it has something to do with the compiler apparently being 32-bit, as I have a 64-bit system. The executable is listed in Eclipse as "HelloWorld.exe - [x86/le]." (Minus the period.) My program in full is below:

#include <iostream>

using namespace std;

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

我还刚刚发现,即使使用未经修改的代码和设置,在Eclipse中创建新的"HelloWorld" C ++项目也绝对无法解决问题.有人对为什么会发生有任何建议吗?

I've also just discovered that creating a new "HelloWorld" C++ project in Eclipse does absolutely nothing to fix the issue, even using the unmodified code and settings. Anyone have any suggestions as to why this would happen?

调试信息:运行程序后:

Debugging information: Upon running the program:

Hello World!
Program received signal SIGNILL, Illegal instruction.
0x6fccc3c0 in libstdc++-6!_ZSt4cout ()
    from C:\Windows\SysWOW64\libstdc++-6.dll
(gdb) bt
#0   0x6fccc3c0 in libstdc++-6~_ZSt4cout ()
    from C:\Windows\SysWOW64\libstdc++-6.dll
#1   0x6fc8908c in libstdc++-6~_ZSt4cout ()
    from C:\Windows\SysWOW64\libstdc++-6.dll
#2   0x004013be in libstdc++-6~_ZSt4cout () at HelloWorld.cpp:4
(gdb)

应该注意,该类的第4行现在指向cout调用.

It should be noted that line 4 of the class now points to the cout call.

推荐答案

在查看了gdb的回溯之后,问题似乎出在C ++运行时 libstdc ++.dll 不兼容.

After looking at your gdb backtrace, the problem appears to be an incompatible C++ runtime libstdc++.dll.

如果您是在现有安装上安装MinGW,则可能会发生这种情况.发生这种情况的另一种方式是,如果某些需要 libstdc ++.dll 的第三方程序将其依赖项安装到您的 Windows \ SysWow64 中,因此可以在系统范围内找到它.问题当然在于, libstdc ++ 的不同版本在ABI级别上彼此不兼容.使用给定的Mingw g ++版本编译的程序需要加载特定Mingw安装随附的相应 libstdc ++.dll .

This could happen if you're installing MinGW over an existing install. Another way this could happen is if some other third party program needing libstdc++.dll installed its dependencies into your Windows\SysWow64 so it could be found system wide. The issue is of course, differing versions of the libstdc++ aren't compatible with each other at the ABI level. Programs compiled with a given Mingw g++ version needs to load the corresponding libstdc++.dll that came with that particular Mingw install.

打开一个新的cmd.exe提示符,并将路径环境 set 设置为当前 mingw \ bin 安装目录.例如,如果您的mingw安装位于 c:\ mingw32-4.7.2 :

Open a new cmd.exe prompt and set the Path environment to your current mingw\bin install directory. For example, if your mingw install is in c:\mingw32-4.7.2:

C:\>set path=C:\mingw32-4.7.2\bin

然后尝试再次运行helloworld.exe.如果它运行完成而没有崩溃,则可能是问题所在.在这种情况下,您应该从 windows \ syswow64 中删除libstdc ++.dll.

Then try running helloworld.exe again. If it runs to completion without crashing then that is likely the problem. In this case you should remove the libstdc++.dll from windows\syswow64.

这篇关于用MinGW编译的C ++ HelloWorld程序会因“非法参数"而崩溃.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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