Dynamic loading shared libraries

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic loading shared libraries

theo-6
Am I right, that with fpc it is only possible to write bindings for
dynamically loading shared libraries (using LoadLibrary) the hard way?
Meaning declare function like:
init_alloc_root : procedure(root: PMEM_ROOT;block_size :
Cardinal);extdecl;    
and then using GetProcedureAddress like:
pointer(init_alloc_root) :=
GetProcedureAddress(Mysql3_comLibraryHandle,'init_alloc_root');

Is there a tool for converting sources with static bindings to this?
Does h2pas have an option for this?

Thank you.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic loading shared libraries

Jonas Maebe-2

On 11 Aug 2009, at 21:18, theo wrote:

> Am I right, that with fpc it is only possible to write bindings for  
> dynamically loading shared libraries (using LoadLibrary) the hard way?
> Meaning declare function like:
> init_alloc_root : procedure(root: PMEM_ROOT;block_size :  
> Cardinal);extdecl;    and then using GetProcedureAddress like:
> pointer(init_alloc_root) :=  
> GetProcedureAddress(Mysql3_comLibraryHandle,'init_alloc_root');

How would the easy way be?

> Is there a tool for converting sources with static bindings to this?

Not that I know.

> Does h2pas have an option for this?

-p


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic loading shared libraries

Jonas Maebe-2

On 11 Aug 2009, at 21:25, Jonas Maebe wrote:

> On 11 Aug 2009, at 21:18, theo wrote:
>
>> Does h2pas have an option for this?
>
> -p

Sorry, -P


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic loading shared libraries

theo-6
In reply to this post by Jonas Maebe-2

> How would the easy way be?
>

I've just been looking into some old Kylix sources:

interface
const LibName = '';
function XftDrawCreate(display: PDisplay; win: XID; vis: PVisual;
colorm: longint): PXftDraw; cdecl;

implementation
function XftDrawCreate(display: PDisplay; win: XID; vis: PVisual;
colorm: longint): PXftDraw; cdecl; external LibName;

initialization
 if dlopen('libXft.so', RTLD_LAZY or RTLD_GLOBAL) = nil then

I can't remember if the extra declaration in the interface section was
necessary.
But by simply settting Libname to empty string and using dlopen I could
switch from static do dynamic afair.

Thanks for the h2pas hint.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic loading shared libraries

Florian Klämpfl
theo schrieb:

>
>> How would the easy way be?
>>
>
> I've just been looking into some old Kylix sources:
>
> interface
> const LibName = '';
> function XftDrawCreate(display: PDisplay; win: XID; vis: PVisual;
> colorm: longint): PXftDraw; cdecl;
>
> implementation
> function XftDrawCreate(display: PDisplay; win: XID; vis: PVisual;
> colorm: longint): PXftDraw; cdecl; external LibName;
>
> initialization
> if dlopen('libXft.so', RTLD_LAZY or RTLD_GLOBAL) = nil then
>
> I can't remember if the extra declaration in the interface section was
> necessary.
> But by simply settting Libname to empty string and using dlopen I could
> switch from static do dynamic afair.

Yes, this was possible with Kylix, however, it requires the usage of PIC
also inside the caller.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic loading shared libraries

theo-6

> Yes, this was possible with Kylix, however, it requires the usage of PIC
> also inside the caller.
>  
Thanks for the information.
It's good to know about the h2pas option.
I was not aware of it. In the many options --help show, it is described as

        -P                 use proc. vars for imports

I was looking for something like "dynamic"

Regards Theo

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic loading shared libraries

leledumbo
Administrator
> I was looking for something like "dynamic"
http://www.freepascal.org/docs-html/user/usersu84.html
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic loading shared libraries

Jonas Maebe-2

On 12 Aug 2009, at 06:46, leledumbo wrote:

>> I was looking for something like "dynamic"
> http://www.freepascal.org/docs-html/user/usersu84.html

That "dynamic" keyword is completely unrelated to importing external  
functions (both in FPC and in Delphi/Kylix).


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal