Wednesday, November 4, 2015

How to reduce .exe file size of your program

http://lazplanet.blogspot.co.id/2013/03/how-to-reduce-exe-file-size-of-your.html

By default, Lazarus makes EXEs including debug information which makes them extremely big. You can strip out this debug information easily and make your EXEs smaller. Here's how to...



Lazarus produces executables that are big in size, almost 14 MB or more. This increased size is of no lame excuse. The big EXE contains debugging information. Expert programmers know that debugging is crucial for testing complex code to make sure they work correctly. And sometimes debugging becomes absolutely necessary when a bug (or an error in the code that fails the program) appears in the program. You don't want to use any faulty program do you? Debugging helps to better analyze what is going on in background, when the program is running.

Don't worry, you can reduce the EXE file size to 1.3 MB or even below 700 KB. Here's how:

a) Using Strip or Changing Project Settings (comes down to ~1.3MB)
b) Using UPX (comes down to below 700KB, but with disadvantages)

Strip is an utility that comes with FPC which is just an executable that can strip debugging information from an EXE. UPX further compresses the EXE to a minimum size. 

First of Strip-ing. There are two ways to how we can strip an EXE:

Option 1: Adding to Tools Menu

Option 2 requires changing Project settings. But programers are lazy. :-\ We don't have time to change all the settings of hundreds of projects, right? We could just use a menu to do our job. It is better for testing various source codes coming from different authors who did not alter the project settings to Option 2.

First take note of your FPC version. Go to Help -> About. You will see the current FPC version that you are using.

Go to Tools -> Configure External Tools...
Click Add. A dialog box for a new menu item under Tools menu. Enter the following info:
  • Title: Strip current EXE
  • Program Filename: C:\lazarus\fpc\2.6.4\bin\i386-win32\strip.exe
  • (Change "2.6.4" to your FPC version that you noted earlier. If you have installed Lazarus in another directory instead of C:\lazarus , then change it accordingly.)
  • Parameters: --strip-all "$TargetFile()"

Click OK and then OK again. Now you  will see a menu item in the Tools menu:


Test your program by pressing F9 (or Run -> Run). Whenever you are ready to release your EXE, just click it, and within some time the file size will be reduced dramatically. (Details are at the end as a final instruction on how to apply this. Read on...) ...........


http://lazplanet.blogspot.co.id/2013/03/how-to-reduce-exe-file-size-of-your.html