Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are all my C++ programs exiting with 0xc0000139?

Tags:

c++

crash

cygwin

I am trying to teach myself to program in C++ and am using Cygwin on Windows with g++ installed. Everything was going swimmingly until I started to declare string variables. Using string literals with cout causes no issues, but as soon as I declare a string variable the program will no longer run.

#include <iostream>
#include <string>

int main ()
{
  std::string mystring = "Test";
  std::cout << mystring;
  return 0;
}

The preceding code compiles without issue, but when run produces no output. GDB provides me with the following:

(gdb) run
Starting program: /cygdrive/c/Projects/CPP Test/string.exe
[New Thread 8416.0x2548]
[New Thread 8416.0x2510]
[New Thread 8416.0x1694]
[New Thread 8416.0x14f4]
[Thread 8416.0x1694 exited with code 3221225785]
[Thread 8416.0x14f4 exited with code 3221225785]
During startup program exited with code 0xc0000139.

From what I have managed to gather this is some sort of entry point issue with a DLL, but I could be completely wrong.

Does anyone know what I have done wrong or what I have misconfigured and how to fix it?

like image 541
Zell Faze Avatar asked Nov 28 '15 08:11

Zell Faze


2 Answers

Well I'm not sure what the problem was exactly (if anyone knows I'd be grateful!), but I was able to solve it for myself by downgrading from GCC 5.2.0 to GCC 4.9.3.

like image 77
Zell Faze Avatar answered Nov 04 '22 12:11

Zell Faze


Error code 0xc0000139 is issued when windows is failing to load a dll file. A possible cause is having several distinct versions of the compiler installed. This may happen when you install on your PC several SWs that come with embedded mingw - e.g., Visual C, Vagrant, Omnet++.

For me, a simple workaround was to run the program in a different way: Instead of running my SW (Omnet++) from the GUI, I ran it from the mingwenv.cmd command line. This solved the problem.

A smarter solution may be found in the answer of Rudolf from Sep 18, 2017, 11:35:13 AM here. In short, he suggests carefully temporarily changing the system's environment variables; and thus, finding the conflicting erroneous dll's, and removing them. In the answer of Tian Bin below it you can see Figs. explaining it.

like image 29
Itamar cohen Avatar answered Nov 04 '22 14:11

Itamar cohen