Reduce .exe size

How do you reduce the compiled file size?

A simple Hello World Program having 500KB size :-|

Tried -s but still its quite large (8.5 KB) I think.
Last edited on
closed account (zb0S216C)
Excessive sizes are usually caused by inclusion of libraries and features that are unnecessary. For instance, if you had a simple console that did absolutely nothing, but you still included C++'s standard IO library, the size of the entire library will contribute to the overall size of the program. In addition, the compiler is free to add additional code (possibly for optimization reasons) without your knowledge, which may also contribute to the overall size.

Wazzak
Last edited on
@Moschops Thank you,
Seems to be a bit too much for me at this stage to use -nostdlib tag so will just go with -s
It's an excellent question, and exploring it deeper and deeper leads to great understanding of what's in your code.

This is also a good read: http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
Yes but has to have some ASM knowledge to completely know what the two articles are saying.
The path to understanding begins with realising what we do not know. If you understand a little more about the limits of your own knowledge, you are a step closer to breaking those limits.

Also, they're fun to read and what that guy does abusing the ELF header to make it smaller is brilliant.
Last edited on
Topic archived. No new replies allowed.