# Why is my .exe so huge?

This topic is 4843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am currently developing a tetris clone and I wonder why my compiled .exe already needs 500 KB. I am using Code::Blocks with MinGW, and the ".objs" Directory contains merely 75 KB. Is that behaviour normal for a OpenGL/GLFW Application? Are there any options I can change in Code::Blocks to reduce the size of the .exe?

##### Share on other sites
Someone will probably give you a link to an article that'll tell you how to make it smaller.

There is a lot of bloat. Try making a simple project that's just:
#include <iostream>void main(){    std::cout << "Hello World" << std::endl;}

and you'll find that it's in the half-a-meg range. There's a lot of stuff that happens before the main function that really isn't necassary for small programs. It might be necessary for your tetris clone, though.

##### Share on other sites
Maybe it's statically linking the needed libraries in the end? You're always using stuff like libc but I'm not sure how much they increase your size.

##### Share on other sites
Are you building it with debug symbols?

##### Share on other sites
Try passing -O3 (optimizations, can reduce code size, probably by turning off some debugging info, as well as by changing things like = vector.size() into = vector._M_size)

Also, get cygwin and run your .exe through the program "strip", which strips symbol information from the .exe - this is destructive for .DLLs, but unless you're going to be trying to treat an EXE like a DLL and link to it, you don't need no steenking symbol data.

##### Share on other sites
Quote:
 Original post by MaulingMonkeyAlso, get cygwin and run your .exe through the program "strip", which strips symbol information from the .exe - this is destructive for .DLLs, but unless you're going to be trying to treat an EXE like a DLL and link to it, you don't need no steenking symbol data.
strip is included as part of MinGW, so the OP may already have it. Also, with the right option strip can be run on DLLs (--strip-unneeded I think).

The reason MinGW produces such large executables, even in relese mode, is that it has to statically link against libstdc++, which is the gcc implementation of the C++ standard library. On *nix systems, gcc links dynamically to libstdc++, and MSVC links to its own C++ standard library dynamically as well. It's really a gcc + Windows problem.

##### Share on other sites
Quote:
Original post by jdhardy
Quote:
 Original post by MaulingMonkeyAlso, get cygwin and run your .exe through the program "strip", which strips symbol information from the .exe - this is destructive for .DLLs, but unless you're going to be trying to treat an EXE like a DLL and link to it, you don't need no steenking symbol data.
strip is included as part of MinGW, so the OP may already have it. Also, with the right option strip can be run on DLLs (--strip-unneeded I think).

Well whadya know, so it does, so it does :-).

##### Share on other sites
Wouldn't the API he's using matter as well?

##### Share on other sites
Thanks a lot for the strip hint, I managed to shrink my 524 KB .exe down to 270 KB with it. After applying UPX --best (and realising it also has a strip option), I am now down to 91 KB.

##### Share on other sites
Another thing to be aware of when developing C++ applications with MingW is that using the STL will add a significant amount to your executable size. See the MingW FAQ.

1. 1
2. 2
frob
14
3. 3
4. 4
5. 5
Rutin
12

• 12
• 10
• 57
• 14
• 15
• ### Forum Statistics

• Total Topics
632113
• Total Posts
3004182

×