nee
nee

Reputation: 3323

Why does MinGW on Windows not need to link statically?

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.

Upvotes: 0

Views: 373

Answers (1)

Micromuncher
Micromuncher

Reputation: 913

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.

Upvotes: 1

Related Questions