[fpc-pascal] Compiler directive: Shared Library

Jonas Maebe jonas.maebe at elis.ugent.be
Fri Jan 28 21:48:23 CET 2011


On 28 Jan 2011, at 20:49, dibo20 at wp.pl wrote:

> I'm looking at:
> http://www.freepascal.org/docs-html/prog/progch1.html
> ... and can't find any directive which tell me when I'm compiling a shared library. For example:
> 
> unit1
> 
> {$IFDEF shared_lib}
>  Foo: Integer;
> {$ELSE}
>  Foo: Byte;
> {$ENDIF}
> 
> ....
> 
> I always must remember to add own flag in my projects.

Units are not automatically recompiled by the compiler depending on whether it is used by a program or by a shared library. That means that such an ifdef will only work if you would always use the -B parameter (which forces the compiler to recompile all used units). Therefore adding such a define to the compiler will not be done, since it would not have the expected effect in general (most people do not compile their code with -B all the time).

What does exist and what can be used is the IsLibrary variable in the system unit, which will be true at run time if the current code belongs to a library and false if not. It cannot be used in the same situations as an ifdef, but it will always work consistently.


Jonas


More information about the fpc-pascal mailing list