Hello and thank you for providing MinGW-w64!
I downloaded mingw-builds-install.exe (169962 byte, no versioninfo) and installed the builds on Windows 8.1.
Then I compiled a simple hello.cpp:
int main(int argc, char *argv)
std::cout << "Hello!" << std::endl;
std::cout << "Bye!" << std::endl;
using these commands:
i686-w64-mingw32-g++ -o hello.exe hello.cpp
When I run hello.exe, it crashes after displaying
If I run hello.exe from a batch file using the PATH command before as above, it works.
But this is not possible on a user's system, because it is unlikely that this path exists.
Debugging showed that hello.exe loads these DLLs from my GnuPG installation:
C:\Program Files (x86)\GNU\GnuPG\pub\libstdc++-6.dll
C:\Program Files (x86)\GNU\GnuPG\pub\libgcc_s_sjlj-1.dll
This does not work.
To fix the problem I copied both DLLs from the win-builds-32\bin directory to the directory of hello.exe.
Is there a better way possible (perhaps static linking?) and how to do it?
I added options -static -s and got a 498K exe.
How to get only the necessary parts of the libraries into the exe file?
There is no way to decrease the file size of a statically linked GCC-compiled executable any further, except by things like [url=http://upx.sourceforge.net/]UPX[/url], but that is just postprocessing. Just keep in mind a half MB isn't big. It's just relatively larger than with e.g. MSVC. That's because there is C startop code and MinGW-w64 improvements linked into your executable, which MSVC stores in Windows libraries, and thus does not link into the executable.
If you don't want to redistribute the GCC runtime DLLs, you will have to link statically. Note that -static will make you link in all libraries statically, if available. You can use -static-libgcc -static-libstdc++ if you only want those linked statically.
You can diagnose DLL dependencies using Dependency Walker:
You will get detailed information of which DLLs get loaded by an executable and/or DLL.