Lazarus: 跨平台 Free Pascal RAD, 可与Delphi媲美

http://www.lazarus.freepascal.org/

 

What is Lazarus?

Lazarus is a cross-platform integrated development environment (IDE) that lets you create visual (GUI) and non-visual Object Pascal programs, and uses the Free Pascal compiler to generate your executable. Its aim is write once, compile anywhere: you should be able to just recompile your program source code with Lazarus running on another operating system (or a cross compiler) and get a program that runs on that operating system.

Why are the generated binaries so big?

The binaries are big because they include a lot of debug information necessary for using gdb (GNU Debugger).

The compiler has an option to remove the debug information from the executable (-Xs), but due to a bug in the compiler (version 2.0.2 and earlier), this doesn't work correctly. It has been fixed in version 2.0.4 and later of the compiler.

You can use a program called "strip" to remove the debug symbols from the executable file. It is located under Lazarus dir lazarus\fpc\2.4.2\bin\i386-win32\.

Just type "strip --strip-all <your executable file with path>" on the command line.

If you want to make your program even smaller, you could try UPX too. There are downsides to it too however, a more detailed description of the drawbacks of using UPX is given on Size Matters.

It's also important to note that the hello world Lazarus software already includes a huge amount of features. It includes:

  • XML handling library
  • Image handling library for png, xpm, bmp and ico files
  • Almost all widgets from the Lazarus Component Library
  • All of the Free Pascal Runtime Library

So it's very big, but it already includes almost everything a real world non-trivial app will need.

Lazarus executable size starts big, but grows very slowly, because of the how the LCL is architectured, and its use of certain Free Pascal features (RTTI). Projects that don't use the LCL and follow a more simplistic less RAD/designer like approach, more similar to some C++ frameworks are much smaller. This typically requires more manual coding though.

Quick guide to Lazarus/FPC application size reduction (tested with Lazarus 0.9.26)

  • 1. Project|Compiler Options|Code|Smart Linkable (-CX) -> Checked
  • 2. Project|Compiler Options|Linking|Debugging| Uncheck all except

Strip Symbols From Executable (-Xs) -> Checked

  • 3. Project|Compiler Options|Linking|Link Style|Link Smart (-XX) -> Checked

The most important items seem to be 2. For a simple application the executable size should now be 1-3 MB instead of 15-20 MB. At this point you can also try: Project|Compiler Options|Code|Optimizations|smaller rather than faster -> Checked (Warning: this might decrease performance)

  • 4. (Optional) Run UPX <your_executable> to compress your binary by an additional factor of 2-3 (Warning: as indicated above, there are drawbacks to using UPX).

 

 

你可能感兴趣的:(Delphi)