13

Let's say I have created and compiled a simple program using the MinGW 64 (g++ compiler). Running this program on my computer and looking in Process Explorer for what DLL files the program is using I find (among many others):

libgcc_s_seh-1.dll
libstdc++6.dll
libwinpthread-1.dll

These are the only ones that reside under my MinGW installation folder. The rest of the DLL files used reside under C:\Windows.

Question 1:

Are the MinGW DLL files the MinGW C++ runtime libraries (so to speak)? Do they serve the same purpose as for example msvcrXXX.dll (XXX = version of Microsoft runtime library).

Question 2:

If I want to run the application on a different computer which does not have MinGW installed, is it sufficient to include those DLL files listed above (i.e. placing them in the same folder as my executable) to have it run on the other computer (we assume the other computer is also a 64-bit Windows machine). If yes, does this mean we basically ship the MinGW C++ runtime with our executable. If no, why?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jensa
  • 2,792
  • 2
  • 21
  • 36
  • Did you consider publishing your program as a free software (e.g. under GPL license on [github](http://github.com/)....)? Then your users would compile it and use *their* version of MinGW. – Basile Starynkevitch Jul 16 '15 at 09:02
  • 2
    @BasileStarynkevitch No, at this point I am just interested in say giving an application to a friend to run. Like a simple tic-tac-toe game or similar. I were to publish it on github or similar then I would do as you suggested, publish the source code and perhaps a makefile. – jensa Jul 16 '15 at 09:05
  • Then you probably need to explain to your friend how to install MinGW runtime. Please be sure to respect the licenses of MinGW. – Basile Starynkevitch Jul 16 '15 at 09:12
  • I definetely do not intend to violate any license, my question was mostly hypothetical. – jensa Jul 16 '15 at 09:17
  • 3
    You can link the language runtime libraries statically with `-static-libgcc` and `-static-libstdc++`. – Kerrek SB Jul 16 '15 at 09:18
  • @KerrekSB: it is technically possible, but is it legal? – Basile Starynkevitch Jul 16 '15 at 09:19
  • @BasileStarynkevitch: Please ask your lawyer about that. – Kerrek SB Jul 16 '15 at 09:20
  • Not my lawyer, but the OP should ask his lawyer. – Basile Starynkevitch Jul 16 '15 at 09:20
  • 2
    @BasileStarynkevitch: Well, *you* wanted to know. You should not trust the OP's lawyer, and the OP shouldn't trust your lawyer. :-( Back to C++... – Kerrek SB Jul 16 '15 at 09:21
  • @BasileStarynkevitch If I´m not mistaken, this is it: https://sourceforge.net/p/mingw/mingw-org-wsl/ci/21762bb4a1bd0c88c38eead03f59e8d994349e83/tree/LICENSE backeup up by some explanation http://www.mingw.org/license – deviantfan Jul 16 '15 at 09:22
  • Where can I find licences for these libraries particularly: libgcc_s_seh-1.dll, libstdc++6.dll, libwinpthread-1.dll? http://www.mingw.org/license says about "MinGW Runtime", "w32api", "WSL" and "GNU development tools" only. I'm not sure which of these include those dll files. – scrutari Apr 22 '16 at 10:53

5 Answers5

9

libstdc++6.dll is the C++ standard library, like you said.

libwinpthread-1.dll is for C++11 threading support. MinGW-W64 has two possible thread variants: Either use the native Windows functions like CreateThread, but C++11 stuff like std::thread won´t be available then; or include this library and use the C++11 classes (too).
Note that to switch the thread model, you´ll need to reinstall MinGW. Just removing the DLL and not using the C++11 stuff won´t work, the DLL will be required nonetheless with your current install.

libgcc_s_seh-1.dll is something about C++ exception handling.

Yes, it should be sufficient to deliver the DLLs too
(or use static linking and deliver only your program file).

deviantfan
  • 11,268
  • 3
  • 32
  • 49
  • 1
    @deviantfan and jensa can you please tell me what licenses are those files under? (This is related to jensa's question 2) – Nikhil Gupta Mar 28 '17 at 17:19
5

For complicated projects where you're not exactly sure which DLL files need to be included to distribute your application, I made a handy dandy Bash script (for MSYS2 shells) that can tell you exactly what DLL files you need to include. It relies on the Dependency Walker binary.

#!/usr/bin/sh

depends_bin="depends.exe"
target="./build/main.exe" # Or wherever your binary is
temp_file=$(mktemp)
output="dll_list.txt"

MSYS2_ARG_CONV_EXCL="*" `cygpath -w $depends_bin` /c /oc:`cygpath -w $temp_file` `cygpath -w $target`
cat $temp_file | cut -d , -f 2 | grep mingw32 > $output

rm $temp_file

Note that this script would need to be modified slightly for use in regular MSYS (the MSYS2_ARG_CONV_EXCL and cygpath directives in particular). This script also assumes your MinGW DLL files are located in a path which contains MinGW.

You could potentially even use this script to automatically copy the DLL files in question into your build directory as part of an automatic deploy system.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jacob Adamson
  • 116
  • 2
  • 2
4

You may like to add the options -static-libgcc and -static-libstdc++ to link the C and C++ standard libraries statically and thus remove the need to carry around any separate copies of those.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hassen Dhia
  • 555
  • 4
  • 11
  • Are you sure it has any meaning on Windows? I think on Windows `MinGW` links to the system DLL's. It can't be configured, as far as I understand, to be linked to the static ones (Like `/MT` in MSVC). – Royi Oct 01 '20 at 17:11
  • I am pretty sure that when passing those commands that I have mentioned you would have no need to distribute the DLLs – Dhia Hassen Oct 03 '20 at 16:15
2

I used ntldd to get a list of dependencies. https://github.com/LRN/ntldd I'm using msys2 so i just installed it with pacman. Use that and then copy all the needed dependencies

JeffCharter
  • 1,431
  • 17
  • 27
1

There are several major challenges to distributing compiled software:

  1. Compiling the code for all target processors (remember, when it comes to compiled code, you need to produce separate downloads/distributions for each type of instruction set architecture).

  2. Ensuring that the builds are reproducible, consistent, and can be easily correlated with a specific version of the code (and versions of the dependencies).

  3. Ensuring that the build output is self-contained and includes all of its dependencies within it (so that it is not dependent on any other installations that happen to exist on just your system).

  4. Making sure that your code is built and distributed regularly, with updates distributed automatically so that -- in the event of security issues -- you can push out new patched versions.

For convenience and to increase reach, it is nice for non-savvy users to have a prebuilt version that they can install. However, I would recommend sharing the source code as a first step.

Most of these requirements are fairly non-trivial to hit and often require automating not only build process, but also automating the instantiation / configuration of VMs in which the build should take place. However, there are open source projects that can help... for example, check out Gitian.

In terms of bullet point #3, the key thing here is to use static linking... while this does make the binary you distribute much larger (because its dependencies are now baked into the output), it also makes your binary isolated from the version of the libraries on the system (avoiding "dependency hell").

Point #4 is very tricky, but thankfully there are also opensource tools to help here, as well such as cloudup, which provides a way to add auto-updating capability to your application distribution.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Michael Aaron Safyan
  • 93,612
  • 16
  • 138
  • 200
  • Thanks, good points. I take away from the answers I have gotten that it might be better to build/compile the code on their system. Like you said though, for non-saavy users this might not be feasible. Regarding point #3, I would not statically link the DLLs I mentioned in the original post (legal reasons etc.) and I would never distribute these DLLs in anyway. I guess one just have to keep track of the dependencies. If the program only uses standard DLLs (like kernel32.dll, user32.dll etc on a Win-environment) I guess these more or less can be assumed to exist nicely on the target Wincomputer. – jensa Jul 16 '15 at 09:28
  • 1
    Yeah, you typically link in some of the libraries statically (typically any third party libraries that you cannot trust will be on the system or that may exist on the system but with incompatible versions) but dynamically link against any libraries that are provided by the system and can be guaranteed to exist on the system to which you are distributing. – Michael Aaron Safyan Jul 16 '15 at 09:34
  • Thanks, that's what I thought. Sounds very reasonable. – jensa Jul 16 '15 at 09:43