Sign in Join

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

Mailing lists / fpc-pascal / 2009-08

Dynamic loading shared libraries

8 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

theo

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.

Reply by email

Florian Klaempfl
to theo: I've just been looking into some old Kylix sources: interface const LibName = '';…
Show quoted text 22 lines
> 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.

Reply by email

Jonas Maebe
to theo: Am I right, that with fpc it is only possible to write bindings for dynamically loading…
theo wrote 7 lines
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

Reply by email

theo
to Jonas Maebe: How would the easy way be? Not that I know. -p Jonas
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.

Reply by email