[fpc-devel] Dynamically Loading Libraries

Ivo Steinmann ivo_steinmann at gmx.net
Wed Nov 4 15:37:24 CET 2009


Jonas Maebe schrieb:
>
> On 04 Nov 2009, at 02:37, Ivo Steinmann wrote:
>
>> The more important question is: should we do it this way or should I
>> also write a 2nd implementation by modifying the compiler (branched)?
>> Then we don't need an external tool at all.
>
> I prefer the compiler not to be modified for something like this. The
> required functionality is easily implementable without doing so, and
> external linking issues are already hard enough to debug without
> adding another abstraction layer on top that hides in the source code
> how a function is actually being imported.
>
>
> Jonas
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>
you are right of course ;)

but one thing would be nice to have. A compiler switch and/or built in
function to check wheter a symbol is used or not. With this information
is easy to implement "smart loading".

something like

{$SYMTRACING OFF}
// used symbols in this section aren't marked as used.
{$SYMTRACING ON}

and then
{$IF symused(XYZ)}{$IFEND}
or even
a builtin function symused(XYZ): Boolean;



this way it would be possible to create a structure that contains all
symbols including the hint if a symbol is used or not.

const
{$SYMRACING OFF}
  zorba_symbols: array[0..6] of TLibSymbol = (
    (pvar:@create_simple_store; name:'create_simple_store';
inuse:symused(create_simple_store)),
    (pvar:@shutdown_simple_store; name:'shutdown_simple_store';
inuse:symused(shutdown_simple_store)),
    (pvar:@zorba_implementation; name:'zorba_implementation';
inuse:symused(zorba_implementation)),
    (pvar:@Zorba_CompilerHints_default;
name:'Zorba_CompilerHints_default';
inuse:symused(Zorba_CompilerHints_default)),
    (pvar:@Zorba_SerializerOptions_default;
name:'Zorba_SerializerOptions_default';
inuse:symused(Zorba_SerializerOptions_default)),
    (pvar:@Zorba_SerializerOptions_free;
name:'Zorba_SerializerOptions_free';
inuse:symused(Zorba_SerializerOptions_free)),
    (pvar:@Zorba_SerializerOptions_set;
name:'Zorba_SerializerOptions_set';
inuse:symused(Zorba_SerializerOptions_set)),
  );
{$SYMTRACING ON}

Then you can do

LoadLibrarySymbols(libhandle, zorba_symbols);

if one of the used symbols is not present, an exception is raised....



More information about the fpc-devel mailing list