Reducing Executable Size
From WxWiki
Even though disk space and RAM are practically dirt-cheap nowadays, in therory, smaller executables might lead to better cache usage, and could be faster. Moreover, users may be downloading over slow modems, and for paid hosting, server bandwidth might be minimized.
- Make a 'release build' instead of a 'debug build'.
- Use 'BUILD=release' as an argument while executing the makefile in wxWidgets 2.5 and later.
- Use the '-O' flag of your compiler, to optimize for size.
- Disable stuff in setup.h or while running './configure', or by editing include/wx/msw/setup.h manually if using MSVC on Windows.
- Sometimes configure options will cause compiler errors because parts of the library aren't properly #ifdef'ed. Usually these are simple to fix, and patches are appreciated.
- It's been reported that '--enable-no_exceptions' can make quite a difference.
- The libtiff library occupies between 200-300k of code and data. Consider removing tiff support from your program to save space.
- Use an executable packer like UPX or ASPack. Note that packing affects the startup time of an executable because the entire executable has to be paged.
- If you link dynamically (e.g., use wxWidgets as a DLL), you'll end up with a smaller executable, but you'll be required to distribute the wxWidgets DLL, too, which can be quite big. This might be a good option when distributing multiple wxWidgets programs as part of a package, but if you are only distributing one application, you will end up with a smaller package if you statically link wxWidgets since the linker will automatically strip out components that your application doesn't use that it doesn't strip when you create a DLL.
- Use Microsoft Visual C++ instead of gcc (Cygwin or Mingw) on Windows. It does produce smaller and faster executables.
- Use strip --strip-all SOMEBINARY[.exe] if using GCC (any platform)
- Adding --remove-section=.comment and --remove-section=.note saved me 0.31% by removing many copies of "GCC: (GNU) 4.0.1 20050727 (Red Hat 4.0.1-5)"
- Most installers compress the executable for distribution.
[edit] Windows Specific
Win32 Release libraries built by Visual Studio use around 1.2mb of space in your executable when compiled in release mode with the default options. By aggressively stripping options from setup.h it is possible to reduce the size of the library to about 400k, and still have a fairly functional library.
If using Visual Studio 2005, the free MSVC .NET 2003 Toolkit, or older professional Visual C++ editions that come with the optimizing compiler, you can set optimizations to "Minimize Size" instead of "Maximize Speed" (see project properties).
Also, if you have a lot of experience with C/C++ and don't mind delving into some black magic, you can eliminate C runtime stubs and strip other libraries. Don't forget extern "C" _fltused; if using floats. You need to make a function for creating large arrays (it's part of the source in c standard library that comes with MSVC).
See also http://www.nopcode.com/AggressiveOptimize.shtml for a header and some other settings you can set manually to reduce executable size by changing linker alignment and padding.
See Trimming wxWidgets Aggressively for some notes and numbers about reducing executable size under Windows for wxWidgets 2.6 & 2.8
