14

UPDATE:

This turned out to be a compiler issue (I was using MinGW) so a workaround is switching to another compiler (in this case Cygwin).


The (original) question

I'm a student starting to learn C++ by myself and I have come across a problem when trying to work with string

This is my test code (the one that isn't working)

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string myString;

    cin >> myString;
    cout << myString;

    return(0);
}

When I tried to run it, the program just ended and exited before I can input anything, and this is the result when I tried to run from gdb

(gdb) run
Starting program: C:\Users\DANIEL~1\AppData\Local\Temp\sandbox.exe
[New Thread 15036.0x31bc]
[New Thread 15036.0x2db4]
[New Thread 15036.0x2628]
[New Thread 15036.0x2280]
During startup program exited with code 0xc0000139.
(gdb)

When I tried to make the file and run it from cmd

g++ sandbox_string.cpp -o sandbox_string

(I added the _string to separate from the _int makefile, the program is still the same)

I got this error: Entry point not found

After a trip round Google I believe that this problem is related to missing DLLs. How can I know what dll(s) I'm missing and is there a way to make sure I have every dlls ?

There are some points I would like to mention:

• I'm acknowledged that this may be a duplicate to Why are all my C++ programs exiting with 0xc0000139?, but that provided no solution other than downgrading GCC. I tried that and it didn't work. Also in that question someone mentioned about missing DLLs, but provided no further solution.

• If I tried to cin an integer for example:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    int myString;
    cin >> myString;
    cout << myString;
    return(0);
}

It works fine, I can input and the program would output then exit normally:

(gdb) run
Starting program: C:\Users\DANIEL~1\AppData\Local\Temp\sandbox.exe
[New Thread 9120.0x35ac]
[New Thread 9120.0x2c4c]
[New Thread 9120.0x390c]
[New Thread 9120.0x32c0]
7
7[Inferior 1 (process 9120) exited normally]
(gdb)

• My compiler is MinGW, this is my MinGW installer screenshot with (hopefully) every details you need MinGW Installer

• I'm using Atom - a text editor, with a plugin to compile and run C++ code (called "gpp-compiler") because I find it comfortable to stick with one text editor instead of using IDEs, but, if you think there's something else I should be using, please let me know.

• I'm not new to programming but I'm (very) new to C++ so please pardon me if there is any silly mistake, also this also means that I greatly prefer simple answer/solution if possible. But I will have no problem with complicated answer that's accompanied by a proper explanation.

Thanks

Community
  • 1
  • 1
Daniel D.
  • 174
  • 1
  • 1
  • 11
  • _"If I tried to cin an integer for example, it works fine:"_ I'm confused. Obviously the program runs long enough to wait for input (because when you enter `7` you get `7` back and everything's fine). So where is your input in the first example? These cannot be the same programs. – Lightness Races in Orbit Jan 25 '17 at 10:19
  • "MinGW" encompasses a **huge** variety of versions and configurations. Please be specific about your toolchain. – Lightness Races in Orbit Jan 25 '17 at 10:21
  • @LightnessRacesinOrbit I have edited my question with more information: • The first example program exited before I can input anything • I took a screenshot of my MinGW installer which hopefully includes version number and such Thanks – Daniel D. Jan 25 '17 at 14:58
  • Please include relevant details as text, not links to images. – Lightness Races in Orbit Jan 25 '17 at 16:37
  • I ended up solving this problem by switching to CygWin64, thanks anyway. I s there anyway I can close this question or mark it as solved without picking a answer because none of which helped me ? – Daniel D. Jan 26 '17 at 11:43
  • Opinion differs, but I recommend leaving it open and leaving an answer of your own explaining what you did. It's not a full solution but it _is_ a workaround and may help others. Someone might come along in the future and provide a better alternative for future visitors. – Lightness Races in Orbit Jan 26 '17 at 12:05
  • Ooh, well, actually cos this is closed as a duplicate you can't leave an answer, so I guess just leave it as it is :) – Lightness Races in Orbit Jan 26 '17 at 12:05
  • The original issue might be this one: https://stackoverflow.com/questions/18668003/the-procedure-entry-point-gxx-personality-v0-could-not-be-located – M.M May 13 '20 at 04:46

2 Answers2

3

The code seems to have no errors. but as it mentioned above this has been a compiler issue so switching to Cygwin from MinGW has solved the error.

The error code 0xc0000139 appears when mis-configured, important files gone missing or damaged. so switching in to a totally different compiler has solved the problem.

hope this will help to improve this questions value @Daniel D.

Tharusha
  • 635
  • 8
  • 25
  • I noticed that this code will work somewhere else but not my computer, is there any reason you think maybe the cause. Because I tried downgrading and it still doesn't work. Thanks – Daniel D. Jan 25 '17 at 15:17
  • Try adding for the "cin" this code (getline (cin, mystr);) `cout << "What's your name? "; getline (cin, mystr); cout << "Hello " << mystr << ".\n";` – Tharusha Jan 26 '17 at 04:32
  • I tried that too but still didn't work, however I fixed the problem by switching to cygwin – Daniel D. Jan 26 '17 at 11:45
0

your code looks correct. can you post the makefile too?

I'd try on command line something as simple as that: g++ sandbox.cpp -o sandbox

Kasper
  • 685
  • 2
  • 11
  • 30