Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-01

Compiler directive: Shared Library

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jonas Maebe
to Unknown author
Show quoted text 15 lines
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