I installed mingw on my linux computer to compile executable files for windows. The problem is the generated exe files are so large around 5-8mb. Is that normal for mingw compiler? How can I make my compiled code smaller?
Printable View
I installed mingw on my linux computer to compile executable files for windows. The problem is the generated exe files are so large around 5-8mb. Is that normal for mingw compiler? How can I make my compiled code smaller?
You're probably using static linking. If you could use dynamic linking, you would probably end up with a smaller exe, although it will require the appropriate runtime to be installed on the target machine.
Turn off debugging symbols... they bloat the he.. out of software.
The smalest MinGw program ("Hello World") comes in at a rather surprising 200k with no debugging stuff in it.
If executable size is an issue you might try Pelles C ... starting about 20k, 8k for windows... or Tiny C which starts at about 8k.
FALSE. Experiments show that debug info adds another ½ KB for a Hello World program.
What bloats the executable is static linking and debug builds (32 KB vs 8 KB).
(Tested using Visual C++ 2010. Your results on mingw may vary.)
Admittedly, I didn't. My bad.
I don't know how to compile debug vs release builds on mingw, though.
If anyone can prove me wrong, I shall eat those words.
I can vouch that debug info does not bloat executable using Visual C++, though.
Visual C++ produces a big wad of stuff when you compile for debug, it's just that it puts it in a separate file (.pdb). Check out the size of that sucker sometime.
As far as the OP's question, the size is probably due to the massive bloat of whatever C runtime is being used by MinGW (probably GNU).
Are we discussing debug info (ie debug symbols) in the EXE or debug builds (that is, executables built for debugging)?
Debug info tends to be embedded into the exe in both release and debug, and to my knowledge does not bloat the size significantly.
Debug executables on the other hand bloats the size enormously. But they wouldn't run on another machine without Visual Studio installed.
You've either statically linked a huge chunk of code or are grossly exaggerating the size. In the first case, nothing can be done if you need to statically link that much code. (If you don't need to statically link but do need that much code, why aren't you using a dynamically linked library?) In the second case, don't exaggerate about how large the files are.Quote:
The problem is the generated exe files are so large around 5-8mb.
That would be false.Quote:
The smalest MinGw program ("Hello World") comes in at a rather surprising 200k with no debugging stuff in it.
The smallest C program is 8KB with or without the minimum necessary statically linked "libgcc" and no compiler fluff.
The smallest C++ program is approximately 200K or 400K (it depends on the version of "libstdc") with a statically linked "libgcc" and "libstdc++" and no compiler fluff.
The smallest C++ program is approximately 8K with a dynamically linked "libgcc" and "libstdc++".
The MinGW port of "GCC" uses the same "MSVCRT.DLL" runtime as older versions of "MSVC". The only increase in size from this would be tiny because the developers have included a wrapper for some routines to fix some bugs in the DLL. (Obviously, they can't just fix the DLL since it isn't their's.)Quote:
As far as the OP's question, the size is probably due to the massive bloat of whatever C runtime is being used by MinGW (probably GNU).
It does however use "libstdc++", but that weighs in at less than a MB and can be linked dynamically.
Soma
It is actually the debug stuffs that made the size larger.
I just check the makefile of the program that I am compiling and found out that the argument "-g" is included in the parameters that is passed to mingw. I just remove that and the size decreased to 800kb. I believe that enabled the compilation of debug symbols.