1

I'm using the Linux Subsystem to compile an executable for Windows and the executable does not run and shows up with an error saying a DLL is missing.

This is the command I used to compile the executable: i686-w64-mingw32-g++ -o test.exe main.cpp

And this is the code inside main.cpp:

#include <iostream>

int main()
{
    std::cout << "Hello World!" << std::endl;
    return 0;
}

How do I allow my program to run on Windows?

liaquore
  • 403
  • 8
  • 22
  • Where is `libstdc++-6.dll` installed? Is that directory in your `%PATH%`? – Some programmer dude Jun 10 '19 at 09:05
  • Do I need to include it somehow when I'm compiling? I'm new to GCC-type stuff. – liaquore Jun 10 '19 at 09:05
  • On Windows all DLL's either need to be in the command-line program search path (the `%PATH%` environment in Windows console windows), or in the same directory as the executable program that you try to run. – Some programmer dude Jun 10 '19 at 09:08
  • Could I not put the libstdc++-6.dll inside the executable? I've never seen that DLL next to an executable before. – liaquore Jun 10 '19 at 09:09
  • The term DLL is an abbreviation of Dynamic Link Library. It's a library that is loaded dynamically by the Windows operating system when it's running your program. It has worked the same way since DLL's was introduced with Windows 1.0 in 1985. – Some programmer dude Jun 10 '19 at 09:14
  • If it's dynamically loaded by Windows, why can it not be found when my program in particular is ran? – liaquore Jun 10 '19 at 09:16
  • Like I said before, it either has to be in the same directory as the `.exe` file, or in a directory in the `%PATH%` environment. – Some programmer dude Jun 10 '19 at 09:18
  • So if that DLL contains the standard library with iostream and that type of stuff, does that mean most other programs would have that DLL as well? – liaquore Jun 10 '19 at 09:22
  • An alternative to Linux on Windows is [Microsoft Build Tools](https://devblogs.microsoft.com/cppblog/visual-studio-build-tools-now-include-the-vs2017-and-vs2015-msvc-toolsets/). The Build Tools provide the headers, libraries, compiler, linker, make program, dumpbin and several other developer tools. No need for Visual Studio. No problems from Linux on Windows like missing libraries. – jww Jun 10 '19 at 09:29
  • Please check this answer https://stackoverflow.com/questions/6404636/libstdc-6-dll-not-found – Squirr3l Jun 10 '19 at 09:42
  • Yeah, I tried that and it worked. The only downside is that my Hello World! program executable is now 2 megabytes. – liaquore Jun 10 '19 at 09:43

0 Answers0