std::endl crashes Windows 8, compiled using MinGW

你说的曾经没有我的故事 提交于 2019-11-29 04:01:59
Clifford

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.

I suggest the following experiments:

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) Eliminate the exit code by:

int main()
{
    return 0;
}

3) No newline at all:

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

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).

I had the same issue and found after a long painful search that I had multiple versions of the mingw provided libstdc++-6.dll on my computer. One was part of the mingw installation the others were part of other installation packages (gnuplot and GIMP). As I had gnuplot in my PATH the compiled mingw exe it would use an older, incompatible version of this dll and crash with the described symptoms. I can, therefore, confirm Dietmar Kühl's suspicion. As suggested above linking the library statically obviously helps in this case as the library functions are included in the exe at compile time.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!