Page 1 of 2

How to lower the disk space taken by my programs!

Posted: Mon Jul 11, 2005 5:24 am
by GianT
Hi, I would like to know if you don't know some tips to lower the size of the applications made in c++ or even in other programming language...

I use wxDev-cpp, and I let it create all the basic files for my projects, but I noticed that even for a single window frame, the program takes about 3Mo!!
I don't know if this is due to the compiler...I think that the more librairies are included, the bigger the program will be, but I think that there must be another way...

I would like to share my programs on my future web site, but I don't see myself sharing a program of 3Mb which does nothing else but shutting the computer down (for example, or even saying hello world :D )

I think that every programmer has to deal with this problem one day. Do you know the key to doing this?

Posted: Mon Jul 11, 2005 6:10 am
by uqkobi
Hi,

In Linux you can use the command line tool "strip"

Hope that helps.

Posted: Mon Jul 11, 2005 6:12 am
by Jorg
Well ofcourse you can do this:

- Compile wx with optimized for size
- Make sure you compile a release version
- Use UPX (and lowjoel's great GUI for it) to compress the exe
- If all fails, build a wx lib with a lot of settings switched off. It is a pity there isn't such a config tool as the linux kernel has, to make it easy to configure it and remove / add stuff.

That's about the basic way to reduce size...

- Jorgen

Posted: Mon Jul 11, 2005 6:28 am
by GianT
uqkobi wrote:Hi,

In Linux you can use the command line tool "strip"

Hope that helps.
Maybe it will help others, but not me, I work under Windows XP.Thanks
Jorg wrote: - Compile wx with optimized for size
Well, I don't know what you mean, but in the project options/compiler, there is an option set to better optimisation.
Jorg wrote:- Make sure you compile a release version
Same as upper, I don't know how to do this...The only time I saw the word "release" was when I was entering the version information in the project options.
Jorg wrote:- Use UPX (and lowjoel's great GUI for it) to compress the exe
Yeah, I had forgotten this stuff :oops: Btw, where can I find lowjoel's program?
Jorg wrote: If all fails, build a wx lib with a lot of settings switched off.
lol not possible for the moment, if only this could be done in less than an hour... :)

Posted: Mon Jul 11, 2005 8:42 am
by Marmis
lowjoel's UPX with GUI can be found on his website: joelsplace.sg/studyroom/index.php

I'm not sure whether or not it's working at the moment, I for one couldn't access it. Hope it works for you though.

Posted: Mon Jul 11, 2005 1:32 pm
by Tyler
GianT wrote:Same as upper, I don't know how to do this...The only time I saw the word "release" was when I was entering the version information in the project options.
Build > Set Active Configuration > Release

Now compile. This will strip all of the debugging information out of your executable (which your users don't need anyways). This step alone takes my executable from 4.92 MB to 2.37 MB.

Posted: Mon Jul 11, 2005 4:51 pm
by Digi
@Tyler: Thats for Visual Studio, hes talking MinGW/DevCPP.


To optimize in DevCPP, go to Projects -> Project Options -> Click Compiler Tab -> Click Optimiztions -> Make Best Optimizations say Yes

For me this is enabled by default. However my Executables still get bloated. The reason for this is GCC, it Bloats exe files. As seen with some game engines.

Posted: Mon Jul 11, 2005 6:32 pm
by GianT
Marmis wrote:lowjoel's UPX with GUI can be found on his website: joelsplace.sg/studyroom/index.php
Ok, gonna take a look at this.
Digi wrote:To optimize in DevCPP, go to Projects -> Project Options -> Click Compiler Tab -> Click Optimiztions -> Make Best Optimizations say Yes

For me this is enabled by default.
Mine is also enabled by default...

Posted: Mon Jul 11, 2005 10:30 pm
by GianT
Ok! With the UPX compresser, I manage to take the size down to 600ko! I expected less, but it is far better than the 3Mo of the beginning.
Thanks.

>>Jorg: if you could explain what I didn't understand, maybe I could have a better result. Btw, I think you should put a thread in the FAQ which subject should be the subject of the current thread. This could help a lot of people.

Posted: Wed Jul 13, 2005 9:03 pm
by leio
http://wiki.wxwidgets.org/wiki.pl?Reduc ... table_Size

---
As for strip being only on Linux supposedly - I believe that as mingw32 is basically gcc, then strip also exists to strip the executables made by mingw32 on Windows.

Posted: Mon Jul 18, 2005 6:23 pm
by j_pilborough
Executable size seems to have about doubled between 2.4 and 2.6, I don't know why. Linking time also seems to have increased. Maybe it's something to do with having more libraries, or maybe increasing the overall size increases the overhead in the library.

Posted: Tue Jul 19, 2005 6:55 am
by llama9000
There is also the strip util that comes with Cygwin.

Personally I've found that you can use both strip and upx (in that order) to further reduce the executable size. Does wonders for me at least. :D

Posted: Tue Jul 19, 2005 7:01 am
by upCASE
Hi!
Just a sidenote:
When stripping the executable it usualy gives better results to do it at compile time instead of running "strip" on it. Using gcc use the -s switch to enable stripping when compiling.

Posted: Tue Jul 19, 2005 7:05 am
by lowjoel
well ya i know there are bugs in my upxgui.... so cast your vote on http://forums.wxwidgets.org/viewtopic.php?t=2977 on whether I should start a sf project for it... i wanna know...

and those who choose yes and what to help dev it, PM me and lemme know

thanks
joel

P.S. at this point in writing upxgui is a "wrapper" it just calls on it. i might like to integrate it, but not that this time. so ur vote counts!

Posted: Tue Jul 19, 2005 8:48 am
by Ryan Norton
Use MSVC and set to optimize for size, then run UPX on it and you should get at the very least under a meg.