2

I just recently downloaded Code::Blocks for c++ use, and I'm getting an error for this code:

#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
    string name;
    cin >> name;
    cout << "hello, " << name << "\n";
    system("pause");
}

The error says:

The procedure entry point _ZNSt7_cxx1112basic_stringlcSt11char_traitslcESalcEEC1Ev could not be located in the dynamic link library (path)

Everything compiles perfectly, and it runs properly in the IDE, but when running the executable it gives me the error. I'm using the mingw compiler. Any help is appreciated!

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
SamelCamel
  • 67
  • 2
  • 9
  • add `#include ` on your code – eyllanesc Apr 19 '17 at 21:51
  • @eyllanesc It didn't seem to fix it, I still got the same error. – SamelCamel Apr 19 '17 at 21:58
  • Your executable is static linking to an external DLL that does not export the `std::basic_string` class, but the compiler/linker emitted a reference to that DLL. So either you have the wrong version of the DLL for your executable to use, or you should tweak your project settings to remove the external linkage to begin with. – Remy Lebeau Apr 19 '17 at 22:02
  • @RemyLebeau I did link `-static-libstdc++` to the project because I can't run the executable without it. Would that be the problem? – SamelCamel Apr 19 '17 at 22:04
  • What happens is that your executable is using a dynamic library, your IDE is adding it, but when you use it from the cmd you must do it manually. – eyllanesc Apr 19 '17 at 22:04
  • You could search for the .dll file – eyllanesc Apr 19 '17 at 22:05
  • see this: http://stackoverflow.com/questions/2463243/dll-search-on-windows – eyllanesc Apr 19 '17 at 22:07
  • @eyllanesc I think it has something to do with strings because any executable that I created runs fine, it's just when I add strings that the error appears. I could also be entirely wrong because I just started c++ recently. – SamelCamel Apr 19 '17 at 22:08
  • That is what I say, when using the string class, this uses a dll, the IDE calls it and so you can use it, but in the cmd does not happen that, I recommend looking for the dll that contains the implementation of string.h , Find a file called string.dll or similar and copy it into the same folder as your executable – eyllanesc Apr 19 '17 at 22:13
  • 2
    If you use MinGW, then copy libstdc++-6.dll and libgcc_s_dw2-1.dll into the same folder as your executable. – salted Sep 02 '17 at 22:44

0 Answers0