std :: endl会崩溃Windows 8,使用MinGW编译 [英] std::endl crashes Windows 8, compiled using MinGW

查看:285
本文介绍了std :: endl会崩溃Windows 8,使用MinGW编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3台电脑,其中两台使用Windows 8.使用最新版本的MinGW的g ++(4.8.1-4)我的hello世界程序冻结时,无论我在Windows 8计算机上,而不是在Windows 7中编译和运行。

I have 3 computers, two of which use Windows 8. Using the latest version of MinGW's g++ (4.8.1-4) my hello world program freezes whenever I compile and run on the Windows 8 computers but not in Windows 7.

#include <iostream>
int main()
{
    std::cout << "Hello, World!" <<std::endl;
    return 0;
}

这在g ++中编译得很好,但是运行a.exe会显示世界!那么一个窗口会弹出并说a.exe已停止工作,Windows可以在线检查解决方案...等。

This compiles just fine in g++ but running a.exe will display "Hello, World!" then a window will pop up and say "a.exe has stopped working, Windows can check online for a solution to the program...." etc.

有任何人看到这个问题。

Has anybody seen this problem.

此外,我试过std :: cout<<Hello,World!\\\
<< std :: flush; 。这也有同样的问题。看起来每个刷新缓冲区的函数都会导致崩溃。

Also, I tried "std::cout << "Hello, World!\n" << std::flush;" and this has the same problem. It seems that every function that flushes the buffer causes a crash.

按照Eric的建议,我重新编译了程序并运行在gdb中,并得到以下输出:

Following Eric's advice, I recompiled the program and ran it in gdb and got the following output:

Program received signal SIGILL, Illegal instruction. 
0x00405065 in _Jv_RegisterClasses ()


推荐答案

第二个实例,'\\\
'应该导致输出刷新在任何情况下,虽然在Windows我相信控制台输出立即(或者可能是短暂的超时后自动)在任何情况下没有显式刷新。

In the second instance, the '\n' should cause an output flush in any case, although in Windows I believe console output is immediate (or perhaps automatic after a short timeout) in any case without an explicit flush.

我建议进行以下实验:

1)通过使用C库来查看它是否特定于C ++库使用C运行时而不是glibc):

1) See if it is specific to the C++ library by using the C library (in MinGW Microsoft's C runtime is used rather than glibc):

#include <stdio.h>
int main()
{
    printf( "Hello, World!\n" ) ;
    return 0;
}

2)通过以下方式消除退出代码:

2) Eliminate the exit code by:

int main()
{
    return 0;
}

3)没有换行符:

#include <iostream>
int main()
{
    std::cout << "Hello, World! ;
    return 0;
}

不同的编译器选项,如优化级别,或 -fno-builtin ,例如,或者建议这里 -static-libgcc -static-libstdc ++ 怀疑`-static-libgcc 本身会有任何效果,因为MinGW使用Microsoft的C运行时DLL,静态库只能用于Microsoft的工具)。

4) Try different compiler options such as optimisation levels, or -fno-builtin for example, or as suggested here: -static-libgcc -static-libstdc++ (although I doubt `-static-libgcc will itself have any effect since MinGW uses Microsoft's C runtime DLL and the static library is only available with Microsoft's tools).

这篇关于std :: endl会崩溃Windows 8,使用MinGW编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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