1

I am writing a simple small program in c++ to test vectors. The following code works well and output hello to the cmd. The steps I follow are: g++ filename.cpp to compile .\a.exe to run

#include <iostream>
#include <vector>
using namespace std;

int main()
{

    cout<<"hello";
    return 0;
}

However, when I declare a vector, the hello does not show and the program seem to not working at all.

#include <iostream>
#include <vector>
using namespace std;

vector<int> a;

int main()
{

    cout<<"hello";
    return 0;
}

I do not get any error message while compiling. But I do get a certain message about no entry point when I run outside the cmd.

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

I searched on google and stack overflow but could not find a solution to my problem.

For anyone who would read this later on, I had something called gtk installed and defined in the environment path variables and it seems like it was colliding with MinGW. Everything runs smooth by writing:

g++ ex1.cpp -static-libgcc -static -static-libstdc++

Sara Kat
  • 378
  • 2
  • 19

1 Answers1

2

The problem is likely caused by the fact that the DLL containing the function the program is trying to access (_ZNKSt9baisc_ioslcSt11char_traitslcEEcvbEv here) is not found by Windows when it tries to execute your program.

There are a few solutions for this :

  • Static linking with the C++ library (--static-libstdc++) (this will directly link the C++ library into your executable (this may make your program bigger))
  • Putting the libstdc++ dll in your program folder (you should be able to find it somewhere in the compiler install folder)
  • Adding the path to the libstdc++ dll to the global PATH variable (If you want to know more about adding to the PATH, see here) so that the dll will be found for any executable running on your computer

Doing any of these should fix your problem.

Gabriel Ravier
  • 358
  • 1
  • 6
  • 17
  • *Putting the dll in your program folder* Avoid doing this. It is easier for a malicious actor to replace the dll and assimilate your computer into the Borg than with properly installed DLLs. – user4581301 Jan 28 '19 at 20:35
  • Putting the libstdc++ dll in your program folder : I tried this earlier it didn't work anyway – Sara Kat Jan 28 '19 at 20:36
  • This works though but why? Static linking with the C++ library (--static-libstdc++) – Sara Kat Jan 28 '19 at 20:36
  • _"Putting the libstdc++ dll in your program folder"_ Better to add the location to the `PATH` environment variable. But the MinGW installation should have already done that. – πάντα ῥεῖ Jan 28 '19 at 20:36
  • @SaraKat Static linking builds the Standard library, at least the parts of it you need, into your program, eliminating the dependency on the dll (which seems to be the wrong one) . The program will often be much larger as a result, but you don't need to distribute the appropriate library dlls with the program. – user4581301 Jan 28 '19 at 20:41
  • Is there a way to make it do this on it's own? or am I in need to add this every time I use vectors? – Sara Kat Jan 28 '19 at 20:46
  • @SaraKat you should not have to do this. Something is broken. The DLL is being found or you would be getting a different error, so the DLL isn't the correct DLL. Why this would be, I cannot say. – user4581301 Jan 28 '19 at 20:50
  • 1
    ok I found out there were 2 versions of this library: C:\Program Files (x86)\GtkSharp\2.12\bin\libstdc++-6.dll D:\MinGW\bin\libstdc++-6.dll one of them might be there because of Unity's monodevelop I assumed – Sara Kat Jan 28 '19 at 20:52
  • 2
    @SaraKat That could do it. [Welcome to DLL Hell](https://en.wikipedia.org/wiki/DLL_Hell) – user4581301 Jan 28 '19 at 21:09
  • It seems like I am having the same issue with rand. – Sara Kat Jan 28 '19 at 22:49
  • Since this was a duplicate should I copy my answer to the other question ? – Gabriel Ravier Apr 28 '19 at 17:19