[Lazarus] How to configure IDE for my own libraries?

Sven Barth pascaldragon at googlemail.com
Thu Sep 2 09:24:33 CEST 2010


Am 01.09.2010 23:58, schrieb José Mejuto:
> Hello Lazarus-List,
>
> Wednesday, September 1, 2010, 11:21:54 PM, you wrote:
>
> FC>  When you put a number of files in a package will the units that are not used
> FC>  by compiled into the program?
>
> If they do not have initialization or finalization sections, and no
> functions are being used I think they are compiled but not linked in.
>
> The initialization and finalization usually introduce non expected
> code in the final program. Example, think in an unit like:
>
> -------------------------------
> unit DoNothing
>
> uses someuses...;
>
> type
>    TMyUselessObject=class(TObject);
>      T: TreeView;
>    end;
>
> var
>    MyUselessObject: TMyUselessObject;
>
> initialization
>    MyUselessObject=nil;
> -------------------------------
>
> The simple reference in the initialization pulls in all the code in
> the unit related to TMyUselessObject even when you do not use
> TMyUselessObject in you code. And as TMyUselessObject uses a TreeView
> (in example) all the TreeView code is pulled in, which finally will
> pull in almost all the LCL even if your code does not use LCL at all.
>
> I'm quite sure about this, but maybe a more authorized voice can
> confirm.
>
> PS: I'm not sure about non referenced global arrays or variables :-?
>

Let's describe this a bit easier (without smartlinking):

All units in a package are compiled, but only units that are directly 
(in uses clause of one of your project units) or indirectly (in uses 
clause of a package unit which is used by your program) used by your 
program are linked into the resulting binary.

Example:
You have a package that contains the following units:
- UnitA (uses no units of the package)
- UnitB (uses UnitC)
- UnitC (uses no units of the package)
- UnitD (usen no units of the package)

Now you have a program that uses the units UnitA and UnitB. Thus the 
units UnitA, UnitB and UnitC are linked into your program, but UnitD is not.

Don't interpret to much "magic" into the packages of Lazarus. It's the 
same as a unit search path, but automatically managed by the IDE and 
only compiled if needed.

Is it clear now?

Regards,
Sven




More information about the Lazarus mailing list