How to lower the disk space taken by my programs!

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
GianT
Earned some good credits
Earned some good credits
Posts: 124
Joined: Wed Mar 16, 2005 5:44 pm
Location: Guadeloupe, French West Indies
Contact:

How to lower the disk space taken by my programs!

Post by GianT » Mon Jul 11, 2005 5:24 am

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?

uqkobi
In need of some credit
In need of some credit
Posts: 8
Joined: Mon Jul 11, 2005 5:48 am
Location: Earth
Contact:

Post by uqkobi » Mon Jul 11, 2005 6:10 am

Hi,

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

Hope that helps.

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Mon Jul 11, 2005 6:12 am

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
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

GianT
Earned some good credits
Earned some good credits
Posts: 124
Joined: Wed Mar 16, 2005 5:44 pm
Location: Guadeloupe, French West Indies
Contact:

Post by GianT » Mon Jul 11, 2005 6:28 am

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... :)

Marmis
Earned a small fee
Earned a small fee
Posts: 15
Joined: Wed Jul 06, 2005 1:44 pm
Location: Finland

Post by Marmis » Mon Jul 11, 2005 8:42 am

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.

Tyler
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 246
Joined: Fri Sep 03, 2004 12:37 am
Contact:

Post by Tyler » Mon Jul 11, 2005 1:32 pm

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.

Digi
Earned a small fee
Earned a small fee
Posts: 10
Joined: Fri Jan 28, 2005 3:53 am

Post by Digi » Mon Jul 11, 2005 4:51 pm

@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.

GianT
Earned some good credits
Earned some good credits
Posts: 124
Joined: Wed Mar 16, 2005 5:44 pm
Location: Guadeloupe, French West Indies
Contact:

Post by GianT » Mon Jul 11, 2005 6:32 pm

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...

GianT
Earned some good credits
Earned some good credits
Posts: 124
Joined: Wed Mar 16, 2005 5:44 pm
Location: Guadeloupe, French West Indies
Contact:

Post by GianT » Mon Jul 11, 2005 10:30 pm

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.

leio
Can't get richer than this
Can't get richer than this
Posts: 802
Joined: Mon Dec 27, 2004 10:46 am
Location: Estonia, Tallinn
Contact:

Post by leio » Wed Jul 13, 2005 9:03 pm

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.
Compilers: gcc-3.3.6, gcc-3.4.5, gcc-4.0.2, gcc-4.1.0 and MSVC6
OS's: Gentoo Linux, WinXP; WX: CVS HEAD

Project Manager of wxMUD - http://wxmud.sf.net/
Developer of wxGTK;
gtk+ port maintainer of OMGUI - http://www.omgui.org/

j_pilborough
Knows some wx things
Knows some wx things
Posts: 27
Joined: Thu May 26, 2005 10:39 am
Contact:

Post by j_pilborough » Mon Jul 18, 2005 6:23 pm

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.

llama9000
Knows some wx things
Knows some wx things
Posts: 30
Joined: Mon May 30, 2005 3:32 am

Post by llama9000 » Tue Jul 19, 2005 6:55 am

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

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Tue Jul 19, 2005 7:01 am

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.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Tue Jul 19, 2005 7:05 am

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!

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Tue Jul 19, 2005 8:48 am

Use MSVC and set to optimize for size, then run UPX on it and you should get at the very least under a meg.
[Mostly retired moderator, still check in to clean up some stuff]

Post Reply