Reputation: 59
I have a .exe compiled using g++ and it runs without problem. But if I want to distribute it, it will require MinGW installed. Is there a way to avoid this?
Upvotes: 4
Views: 9021
Reputation: 10606
Yes you can compile your code to a standalone .exe file with mingw. I do this, cross-compiling c++ code on linux and run it on windows machines.
The point is, you have to link statically.
-fPIC -static -static-libgcc -static-libstdc++
-lmylib
), ensure that the corresponding file libmylib.lib
exists in the library path of your system and that it is not libmylib.dll
. You can not compile a standalone code with a dll linked..dll
, either redistribute it as well (in the same folder as the exe) or get a static compiled version of the library (this might require you to compile the library yourself). On linux there are some static versions of mingw-packages available. For instance "mingw32-LibRaw-static.noarch : Static version of the MinGW Windows LibRaw library"A few links about the g++ compiler and linker options:
Upvotes: 0
Reputation: 11368
I was looking for the exact same solution. This is what works:
To run the executable on Windows, you need these DLLs:
On my system, I found them in /usr/x86_64-w64-mingw32/sys-root/mingw/bin/
. Your programs may not need all of them. Experiment.
The following part is not correct
As for MinGW licensing terms, it seems that the MinGW libraries are either public domain or MIT-licensed, meaning that there is absolutely no problem with redistributing these DLLs — only the development tools are covered by the GPL.
Update
So the redistribution of the DLLs is not straight-forward. The licensing terms I mentioned are for MinGW itself, I believe. You are in any case allowed to use these libraries, but redistributing would need additional care, unless your sofware is released under a license that conforms with the eligibility terms of the GPLv3 + the runtime exception clause. If I find out more, I'll update the answer.
Upvotes: -2
Reputation: 19975
I use MinGW-64 header files and libraries to cross compile Windows applications under Linux. I link the binaries statically so that I don't have to send anything other than the .exe files to a Windows box. I use my clang/LLVM based toolchain (http://ellcc.org) to do the build rather than gcc, but gcc should be able to do the same thing. I've used this technique to compile all the ELLCC tools (C/C++ compiler, binutils, gdb) and it has worked very well.
Upvotes: 0
Reputation: 2034
Your application will run perfectly well on other computers, without requiring MinGW to be installed; what will be required is for you to distribute any DLLs from the MinGW compiler suite, (likely the C++ library DLL, and maybe also the standard C library DLL), upon which your application depends, along with it.
Do note that these DLLs are licensed under the GPL, so your application may need to be licensed under a compatible licence; (IANAL, so you will need to seek legal advice if you plan commercial distribution). Also, you must make provision to distribute GCC source, (and maybe your own source too), to any user of your application who may request it.
Upvotes: -2