views:

191

answers:

4

I am using rad studio 2010 cpp builder. I've created a new SDI application, added a TCppWebBrowser control and a simple button that onclick trigger the .navigate for the TCppWebBrowser, I compiled it and I got a 1.20mb file, I was expecting less than 700kb at least.

How can I reduce the size of the compiled exe?

I don't want to use "build with runtime packages", I know that will make it very small but I want to get all the necessary packages and dependencies inside the exe but maybe I am getting more than I use, I tried unchecking/removing a lot of design packages (in project/options/packages) I don't use but the file size didn't decreased.

Also I was thinking maybe the TForm component that comes with RAD Studio is giving me more stuff than I need and that could make the file bigger, I mean I only need to drop a webbrowser control and a few buttons in the form, maybe there's a minimal form component I could use to replace TForm.

I know I can use a packer like upx, but I still want to reduce the size by like half before packing it.

Any suggestions will be appreciated.

+1  A: 

Debug builds tend to be much larger than their release counterparts. If you're not doing a debug build, you might look into 'stripping' your executable to remove the last vestiges of informational data that has been attached to the binary.

Yea sorry I forgot to mention I'm doing "release build". I will research about the "last vestiges of informational data". Thanks
peterg
-100kb by stripping the relocation section.
peterg
Hrm. Have you removed every #include you possibly can?
Yes but i have been reading in embarcadero forums and it seems that RTTI is involved in the reason of such a big size for such a simple app. I need to keep researching, I think I could need to recompile the vcl packages with some new RTTI directives.
peterg
A: 

It looks like your library of choice is to blame. There is little you can do if your library is the largest component of your application - the simplest fix is to use another library.

Yann Ramin
recommendations?¿
peterg
+2  A: 

this thread has some suggestions:

David Dean - Embarcadero
thanks, i will check it
peterg
A: 

If what you really want is a small executable file, then you should really not use the VCL framework. If low filesize is required you should use the Windows API directly. This will avoid the overhead of the framework. You will most likely end up with some overhead no matter what framework you use, unless you use every single feature of that library. The whole idea of a framework like the VCL is not to produce small executables, but to make it easier and faster for you as a programmer to develop your application.

Besides considering a framework change (or removal) here are some things you should consider as well. Note though that many of these techniques, can have a negative impact on the performance of your compiled executable. Choosing not to use a framework might put you in a situation, where you might have to reinvent the wheel - so to speak - making your code more vulnerable to mistakes. So weigh the consequences before choosing that path.

  • You could consider using an executable packer like UPX this will reduce the executable size, but will have an impact on performance.

  • You can make your compiler optimize for smaller filesize, rather than faster executable as well.

  • If you really desperately need a small executable, then besides not using the VCL framework you should consider not using the RTL and dynamicly linking many of the required functions like memory allocation etc. You can find a good guide on how to do that here: Techniques for reducing Executable size there are actually a lot of useful hints on that page, some of which is already mentioned in the answers here though.

The bottom line though seems to be, that when you are in need of extremely small executables you should not use any of the larger frameworks. VCL has its huge advantages in its ease of use and extensibility, but it is not a space saver.

TommyA
Thanks for the info and the link. I decided to not use vcl, I think I am going to install the old visual studio 6 and learn to code pure win32 there.
peterg
VS6 is really really old and rather unconforming. I believe you can get a free version of the more modern MS compilers.
Mark B