Michael Barrowman
Michael Barrowman

Reputation: 1181

C++ string type not running

I am having difficulty running the following program:

#include <string>
#include <iostream>

using namespace std;

int main()
{
    cout << "First line.";
    string s = "Hello World";
    cout << " After string.";
    return 0;
}

It compiles fine, but produces no output when run.

If I comment out the string s = "Hello World"; line, then the program runs and outputs First Line. After string. as expected.

It seems that whenever I try to declare a string, the program halts. This also happens when the string is inside a function which is not called.

I am building the program in VSCode on Windows and my compiler and version are: g++ (x86_64-posix-sjlj-rev0, Built by MinGW-W64 project) 8.1.0

Upvotes: 0

Views: 466

Answers (1)

Michael Barrowman
Michael Barrowman

Reputation: 1181

I was able to get to the bottom of the problem thanks to @HolyBlackCat's comment, so I will post the answer here for anybody with the same problem in the future.

I ran the .exe through Windows Explorer (double clicking), rather than through command line, and an error window popped up saying:

the procedure entry point __gxx_personality_sj0 could not be located in the dynamic link library

Once I knew the error I was looking for, I found this SO post:

The procedure entry point __gxx_personality_sj0 could not be located in...

As the other post suggests, I ran the libstdc++-6.dll in my command prompt, and another error window popped open saying that the file didn't have an app associated with it. However, the title bar of that window gave me the directory to the incorrect libstdc++-6.dll file.

To solve the problem, I moved the mingw64 directory to the top of my PATH environment variable, so that the libstdc++-6.dll file in that directory would be used first when compiling.

Upvotes: 6

Related Questions