Zell Faze
Zell Faze

Reputation: 1843

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

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?

Upvotes: 11

Views: 9204

Answers (5)

disservin
disservin

Reputation: 334

This happened to me after an installation of git.
C:\Program Files\Git\mingw64\bin ended up having the highest priority in my environment variables.

Basically any test program would take the wrong lib libstdc++-6.dll, so moving my msys64 path C:\msys64\ucrt64\bin to the highest priority fixed the issue for me.

Upvotes: 1

Dave Atkinson
Dave Atkinson

Reputation: 54

Answering because I don't have the rep to comment - to expand on @Ultra Junkie's comment, I had this issue with a newly-installed copy of MSYS2, just trying to compile helloworld in C++. I used Sysinternals' Process Monitor to look at all system call by my failing helloworld.exe, and discovered that it was finding a version of libstc++6 from an installation of QEMU, and not from C:\msys64\ucrt64\bin, which helloworld was expecting. I deleted QEMU, and helloworld immediately started to run correctly. Not sure what I'll do when I next need QEMU, but yes, the problem can be caused by a program finding an incompatible version of a DLL that it is searching for.

Upvotes: 0

Itamar cohen
Itamar cohen

Reputation: 89

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.

Upvotes: 6

PJ127
PJ127

Reputation: 1258

I had the same problem while mixing up a Release and a Debug build, using Windows 10, mingw compilation and gcc-8.1.0.

I solved it by cleaning and recompiling everything:

cd ${MY_BUILD}
make clean
cmake ${MY_SOURCE} -DCMAKE_BUILD_TYPE=Debug
make -j4
gdb ./bin/my_program.exe # -> works
./bin/my_program.exe # -> no more problem

Upvotes: 0

Zell Faze
Zell Faze

Reputation: 1843

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.

Upvotes: 2

Related Questions