3

During the development of a simple example (I haven't programmed C++ for some time) I encountered a weird behaviour. Following hello world program crashes under Windows (Mingw):

#include <iostream>

int main () {

    for (int idx = 0; idx < 5; idx++) {
        std::cout << "Hello World" << std::endl;
    }

    return 0;
}

If I remove std::endl the program does not crash though.

I use following commands to compile and execute the example, with Mingw32 (g++ 4.8.1) on a 64bit system and OS:

g++ example.cpp -o example.exe
example.exe

The error message is:

example.exe does not work any longer...

Is this a known issue or an obvious mistake of mine?

JBentley
  • 6,099
  • 5
  • 37
  • 72
nils
  • 1,362
  • 1
  • 8
  • 15
  • 1
    The very meaningful report from Windows "example.exe does not work any longer..." – nils Jun 17 '14 at 11:38
  • 1
    What version of mingw are you using? Are you using 32bit or 64bit system and compiler? Looks like a library version clash – Erbureth Jun 17 '14 at 11:39
  • I am using Mingw32 (with g++ 4.8.1) on a 64bit system and OS. But a 32bit application should usually not be a problem on a 64bit system. I could of course test Mingw-w64... – nils Jun 17 '14 at 11:41
  • Please do test it. And yes, I agree, 32bit apps should work with no problems, I suspect some misconfiguration in your build system, however I don't know much about Windows. – Erbureth Jun 17 '14 at 11:43
  • Try to catch an exception - maybe one is thrown? – Spook Jun 17 '14 at 11:44
  • @Spook I am wondering, how he would display it :) – Erbureth Jun 17 '14 at 11:45
  • 1
    @Erbureth `OutputDebugString`, for instance. – Spook Jun 17 '14 at 11:46
  • @Spook: If I use try-catch I get another error showing that "__gxx_personality_v0" has not been found. Maybe it is indeed a misconfiguration of the whole build system. – nils Jun 17 '14 at 11:47
  • You could have sent a bug report, if we'd believe in such a crash in normal environment. – SChepurin Jun 17 '14 at 11:47
  • Wild guess, maybe it's a privileges related problem, e.g. run the console as administrator? – hauron Jun 17 '14 at 11:51
  • @SChepurin: Where? You mean for Mingw? – nils Jun 17 '14 at 11:51
  • @hauron: Does not work either. – nils Jun 17 '14 at 11:52
  • @user3575404 - relatively rare visitors here run g++ under Windows (in mingw), and sure they could not reproduce this crazy behavior. – SChepurin Jun 17 '14 at 11:55
  • what if you try `g++ -m32 example.cpp -o example.exe` – Blood-HaZaRd Jun 17 '14 at 12:10
  • Probably the same issue as this http://stackoverflow.com/questions/14368482/mingw-compiled-programs-crash-on-64-bit-windows. Or this http://stackoverflow.com/questions/20621639/stdendl-crashes-windows-8-compiled-using-mingw. – ks1322 Jun 17 '14 at 12:12
  • Can you confirm that you are using a consistent implementation of headers/compiler and shared library for the standard C++ library? – Dietmar Kühl Jun 17 '14 at 12:19
  • @Blood-HaZaRd: It still crashes. – nils Jun 17 '14 at 13:02
  • @ Dietmar Kühl: No. How? – nils Jun 17 '14 at 13:03
  • @user3575404 What IDE are you using ? or are you just compiling the code via Dos ? – Blood-HaZaRd Jun 17 '14 at 13:37
  • I would argue that when this crashes, your installation is somehow corrupted and you might consider reinstalling everything. – PlasmaHH Jun 17 '14 at 21:05
  • @PlasmaHH: Funny thing is: I just installed it. – nils Jun 18 '14 at 06:42
  • @Blood-HaZaRd: Currently just via dos. – nils Jun 18 '14 at 06:42
  • I see now that the problem does not occur with the cygwin implementation. Guess it is some kind of a misconfiguration or bug with mingw then. I will try and report this as a bug. – nils Jun 18 '14 at 07:41

1 Answers1

0

<< endl is a manipulation essentially a function. your output cant be flushed which is causing problems.

AtPython
  • 193
  • 3
  • 11