Lazarus Faq/ar

From Free Pascal wiki
Revision as of 13:46, 20 May 2010 by A.atalla (talk | contribs) (New page: ===لماذا يكون حجم الملف التنفيذي الناتج كبير ?=== تكون الملفات التنفيذية كبيرة لاحتوائها علي معلومات الت...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

لماذا يكون حجم الملف التنفيذي الناتج كبير ?

تكون الملفات التنفيذية كبيرة لاحتوائها علي معلومات التنقيح (debug information) واللازمة لعمل (gdb منقح جنو ).

المفسر يحتوي علي خيار لأزالة هذه المعلومات من الملف التنفيذي (-Xs),ولكن نظرا لوجود علة في المفسر (الاصدار 2.0.2 وما قبله ),فإنه لا يعمل جيدا . تم إصلاح هذه العلة بدءا من الاصدار 2.0.4 من المفسر.

كذلك يمكنك أستخدام برنامج strip لأزالة معلومات التنقيح من الملف التنفيذي . وتجده عادة في المسار

lazarus/pp/bin/i386-win32/.

كل ما عليك هو تنفيذ اﻷمر

strip --strip-all <your executable file with path>

إذا أردت تصغير حجم البرنامج أكثر عليك تجربة UPX أيضا .UPX أداة رائعة لضغط الملفات التنفيذية ,كما أنه سريع في عملية فك الضغط (حوالي 10 ميجا بايت في الثانية علي معالج بنتيوم 133)

فقط عليك تنفيذ اﻷمر

upx <your executable file with path>

بعد أستخدامك لهاتين الوسيلتين للضغط سيصبح برنامج بواجهة رسومية بسيط في لازاروس بمساحة

  • حوالي 700 كيلو بايت في أنظمة لينوكس .
  • حوالي 420 كيلوبايت علي أنظمة ويندوز .


مزيد من التفاصيل عن أستخدام UPX تجدها في 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 Free Pascal compiler and the way lazarus forms operate. A c++ project (just an example, but applies to other languages / tools too) starts very small on the hello world, but quickly grows exponentially when you need features to write a non-trivial application.

Lazarus vs cpp.png


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

Chart of default sizes for an empty Application with various settings and operating systems

Well I ran tests I did on Lazarus 0.9.29 with FPC 2.4 (FPC 2.2.4 with Windows). Optimized compiler mean using the advices above but without using UPX. Default Lazarus means as installed from package/setup. LCL without debug informations mean after rebuilding Lazarus IDE and LCL without debug informations (-g-).

    Default Lazarus     LCL without debug informations
Ubuntu 64 bits / Lazarus 64 bits
Default application     13,4  Mb     7,5 Mb / 8
Optimized compiler     4,4 Mb     2,70 Mb (0.29svn FPC2.4 2,5)
   
Ubuntu 32 bits / Lazarus 32 bits
Default application     19,6  Mb     5,7 Mb
Optimized compiler     2,9 Mb     1,6 Mb
   
Windows XP 32 bits / Lazarus 32 bits
Default application     11,8 Mb     2,14 Mb
Optimized compiler     1,62 Mb     1,50 Mb
   
Windows Seven 64 bits / Lazarus 64 bits
Default application     12,3  Mb     3,20 Mb
Optimized compiler     2,14 Mb     2,16 Mb