I'm building a C application on Windows using Msys2 and MingW.
This application will be shipped to Desktop Windows machines of end users who are not tech-savvy. I have two questions regarding this:
What is the best practice way to ship a Windows program built using Msys64 and MingW, to a different Windows machine which doesn't have these installed? Some sources on the internet and here on SO say we have no choice but to distribute the exe
file in the same directory along with the MingW dll
s it depends on. Or, to statically link the exe
with the MingW dll
s. But, I'd like to make sure if these are indeed the standard ways to do so. It seems odd that MingW wouldn't have a better way.
Suppose the said exe
also at some point uses LoadLibrary
API to dynamically load a dll
(think plugin system). That dll
was also built using MingW
(and in this case of course will be shipped to end users along with the exe
). Is there anything special I need to do to make sure that the dll
will be loaded successfuly on a user machine without MingW installed?
In addition to 2: does the said DLL need an import library (.lib
) present during compilation on the development machine, and/or during launch on the end machine?
EDIT: Please let me clarify, I am not using MSYS2 as a command line shell. I am working directly with the Mingw gcc
through the Windows cmd
, and have simply obtained Mingw from inside the MSYS2 download directory.
I assume this question is about MSYS2 and mingw-w64 , since there is no such thing as "msys64" .
MSYS2 offers three different target systems:
each of which have entirely separate source trees for their development tools and packages under the MSYS2 installation.
This is not to be confused with different build systems -- the build system can be either Win32 or Win64. For example if you chose Win64 as the build system and chose to install all three target systems then you will have have trees msys64/mingw32
, msys64/mingw64
, and msys64/usr
The MSYS2 installer creates startup scripts for each target that you installed.
If you target Win32 or Win64, then the compiled binaries (exe or dll) can be distributed as standalone products. You can do a static build with gcc or clang , producing a single standalone executable, or you can do a build that depends on DLLs which you distribute with your executable.
It is standard for binary distributions to include all files that they require and are not provided by the target operating system, this is not a peculiarity of mingw-w64.
The LoadLibrary
search path is described in the MSDN documentation .
If you target MSYS2 then the resulting binary SHOULD be run under a MSYS2 shell. This target offers some POSIX features that are not supported directly by mingw-w64. It can be considered a fork of Cygwin. It would be possible to distribute a binary targeting MSYS2 along with a bunch of DLLs copied from the MSYS2 installation that you identify using dependency tracker.