0

I've installed MinGW on my Linux machine and installed the MinGW package, however, I noticed that I can't run my program on Windows machines that don't have MinGW, I looked it up and soon found that the solution to this is to link statically. This worked, but it's still annoying to have to statically link everything and doesn't make much sense. I noticed that on my Windows machine where MinGW was installed I could compile a program without statically linking anything and the program would run successfully on any Windows machine regardless of whether it had MinGW installed or not.

My Linux box is running Arch Linux and Installed the mingw-w64-gcc AUR packages if that info helps at all.

Student
  • 805
  • 1
  • 8
  • 11
zee
  • 2,933
  • 2
  • 16
  • 28
  • When the program doesn't run because a dll is missing, it should say which one it is. You can then find it (they should come with mingw-w64, at least on windows they do), and distribute with your application. – HolyBlackCat Aug 08 '18 at 18:52
  • 3
    MinGW does not provide its own C library. Instead, it adapts Microsoft's, which is likely to be available on any Windows system. But it *does* provide other libraries, and if you use one of these in a dynamically-linked executable then you definitely do need it to be present at runtime. That doesn't necessarily need to come from a full MinGW install, but it does need to be there. – John Bollinger Aug 08 '18 at 20:15

1 Answers1

1

Linux and Windows shared libraries / dynamically linked libraries are similar in how they get discovered. Your mingw program works in windows that has mingw installed because the installation likely added DLLs to your search path. Check out this article on DLL search order.

When you statically link, all that library code gets included in your executable.

If you want to share your mingw program with friends, then you need to also install all the shared libraries it uses in their search path. You can use sysinternals listdlls (or other tools) to find your dependencies, and include them in the same directory as your exe or install them to a library path (see the search order article).

You can also check out this article; How do I find out which dlls an executable will load? as it has lots of other options.

Micromuncher
  • 903
  • 7
  • 19
  • I should clarify, because from what I understand your comment says that I can run a program compiled by mingw because mingw is installed on my windows machine. What im telling you is that when a program is compiled with mingw on my windows machine without static linking it can run on any of my other windows machines that DONT have mingw on them, while compiling with mingw on linux requires me to statically link all my libraries to achieve the same effect – zee Aug 08 '18 at 19:28
  • 1
    Ah, so John answered that in a comment. For linux, you need to go through a similar process. Check out http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html and use ldd as mentioned here https://stackoverflow.com/questions/50159/how-to-show-all-shared-libraries-used-by-executables-in-linux – Micromuncher Aug 08 '18 at 21:04