[fpc-devel] Dynamically Loading Libraries
Joost van der Sluis
joost at cnoc.nl
Mon Nov 9 13:07:49 CET 2009
On Mon, 2009-11-09 at 09:14 +0100, Florian Klaempfl wrote:
> Ivo Steinmann schrieb:
> > Delphi have got also a solution:
> >
> > http://docwiki.embarcadero.com/RADStudio/en/Libraries_and_Packages#Delayed_Loading
>
> Soon or later people will request this anyways I fear ...
MeMeMe! ;)
This time a feature I like, while I do not like things like
'for..in' (Because it's not an orthogonal feature, another word I just
learned in respect to programming)
It's a nightmare to maintain external library-headers when all exported
functions have to be declared twice. Once for static loading, and one
for dynamic loading. And the fact that all bindings are really done even
when they are not used is also very annoying. To solve this adding
wrappers for each function..... Means that you have to declare each
exported function three times...
I don't see the problem when the exported function is defined 'static' -
so a link-error happens when it is not available at compile time, and a
error occurs when the program is started while the library is not
available.
Or weak. Which means that a library is loaded when the first call to a
function is made. Then the error of a missing library/exported function
can be given on the moment of the first function call. Nothing special
here?
(In fact the compiler generates the necessary wrapper-function:
Function AExternalfunction(param1: type1): type2;
begin
if not loaded(ExternalLibrary) then
LoadDynamicLibrary(ExternalLibraryName) // if fails exception
if not assigned(TempFunctionVariable) then
@tempFunctionVariable:=GerProcedureAddress(...) // fail->exception
Result := tempFunctionVariable(param1);
)
Joost
More information about the fpc-devel
mailing list