C ++ HelloWorld compiled with MinGW crashes with "Invalid argument"

I decided that the time had come when I learned C ++, and after three hours trying to get the compiler to work, I finally created a working program. However, this would seem to be spontaneously broken when I tried to reorganize the project in Eclipse, cutting it and pasting it into it. The program just crashes, and Windows brings up the dangerous dialog "HelloWorld.exe has stopped working." A bit of debugging showed that "cout" is considered an illegal argument. I looked a little more at this problem, and now I suspect that this is because the compiler is apparently 32-bit because I have a 64-bit system. The executable is listed in Eclipse as "HelloWorld.exe - [x86 / le]". (Minus period.) My program in full is below:

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

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

EDIT: Debugging Information: After starting 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) 

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

0
source share
2 answers

After looking at your backdrace gdb, the problem seems to be incompatible with C ++ runtime libstdc++.dll .

This can happen if you install MinGW on top of an existing installation. Another way this can happen if some other third-party program that needs libstdc++.dll installed its dependencies on your Windows\SysWow64 so that it can be found on the system. Of course, the problem is that different versions of libstdc++ are incompatible with each other at the ABI level. Programs compiled with this version of Mingw g ++ should download the appropriate libstdc++.dll Dll that comes with this particular Mingw installation.

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

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

Then try helloworld.exe again. If it runs to completion without a glitch, this is most likely a problem. In this case, you must remove libstdc ++. Dll from Windows\SysWow64 .

+3
source

Build it statically so you don’t worry about the wrong settings. Just add "-static" to your compiler options.

+2
source

All Articles