0

Language: C++ IDE: Code::blocks Compiler: GNU GCC OS: WIndows

I am trying to create an executable. When I go to the executable file, and I attempt to open it, it says " the code execution cannot proceed because libstc++-6.dll was not found. Reinstalling this program might fix this problem." The problem is that the code works when I run it inside my IDE, but not when I attempt to double-click the executable file itself.

I have done some experimenting and came up with this:

1: This problem only shows up if I am using the iostream library. 2: I have looked in the directories of my compiler, and libstc++-6.dll is indeed there.

This problem has been plaguing me for a while, and I have no idea how to resolve it... Any help is appreciated. Thanks!

EDIT: I couldn’t figure out how to link it statically, if that’s a word. So what I did is I copy-and-pasted three libraries to the same directory as my exe and it worked. The libraries were the ones which my compiler told me were missing. Thanks everyone!

fartgeek
  • 178
  • 3
  • 12
  • 4
    you need `libstc++-6.dll` in the same directory with your executable unless your path settings says otherwise. – macroland Sep 09 '20 at 18:50
  • How exactly are you running your application? Are you double-clicking it in Windows Explorer, running it from a command prompt (and if so, from what directory?), using the Win+R "Run Program" prompt, or launching it in some other way? – Quietust Sep 09 '20 at 18:51
  • 2
    Related: [https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications](https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications) – drescherjm Sep 09 '20 at 18:58
  • The difference is running your code from the IDE will populate the windows PATH environment variable with the folder of your compiler's runtime while clicking on the executable in windows you get no such behavior. You could go into your environment variables in windows and add an entry or copy the required dlls to the same location as the executable, – drescherjm Sep 09 '20 at 19:01
  • A possible alternative: Statically link the Standard library with the `-static` linker option. The executable will be much larger, but you no longer need the dll. – user4581301 Sep 09 '20 at 19:04

1 Answers1

0

Based on libstdc++-6.dll not found, it looks like the problem is that your executable isn't in the same directory as the dll, so either copy the dll file to the directory with your executable, or better: use the static options to link the libraries without needing to copy the dll for each executable.

  • Static linking may solve this problem, but that's not a universally "better" solution than using dynamic linking. – Jesper Juhl Sep 09 '20 at 19:11
  • hmmmm I did it now it says libwinpthread-1.dll not found... – fartgeek Sep 09 '20 at 19:14
  • @JesperJuhl Maybe not universally better - I only meant to imply it may be better in their particular case than copying the dll every time they make a new executable. Obviously for other situations (e.g. in complicated codebases with lots of different projects and dependencies), dynamic linking would be better. But for personal or small projects static linking has benefits. – sleep furiously Sep 09 '20 at 19:14
  • @fartgeek sounds like you need to find that dll and copy it over as well. Or if you took the static linking approach, maybe you need to add the location where that winpthread dll is located to your PATH. See: https://stackoverflow.com/questions/28907304/cc1-exe-system-error-libwinpthread-1-dll-missing-but-it-isnt – sleep furiously Sep 09 '20 at 19:15