7

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?

Zell Faze
  • 1,795
  • 2
  • 13
  • 16
  • 1
    Your code compiles fine and provides the expected output, 'Test', for me on Windows 10 using gcc 4.8.1. Are you experiencing the same problem with other C++-programs or is it in any way related to the code you provided? Also, which compiler flags are you using to compile the code? – JonatanE Nov 28 '15 at 09:07
  • I haven't played around with it too much, but I can get other code to compile. Declaring a string variable seems to be what causes the problem. I haven't tried declaring variables of any other classes so I'm not sure if it is an issue with string or classes in general. I am using GCC 5.2.0-1 on Win10 downloaded with the Cygwin installer. I'm not sure what flags I use, likely the default. I compiled it with g++ -g string.cpp -o string.exe – Zell Faze Nov 28 '15 at 09:15
  • I changed the installed version of GCC to 4.9.3 and my programs now compile and run properly. How strange... – Zell Faze Nov 28 '15 at 09:22
  • You might have updated the GCC but kept the libraries at version 4.9.something, they are separate packages. Binary compatibility is fragile. – Euri Pinhollow Feb 06 '17 at 23:41

3 Answers3

2

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.

Zell Faze
  • 1,795
  • 2
  • 13
  • 16
  • 4
    You may be able to use a tool like Dependency Walker (http://www.dependencywalker.com/) to diagnose problems with missing DLLs. – Michael Burr Nov 28 '15 at 09:52
1

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.

0

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
PJ127
  • 716
  • 8
  • 20