[fpc-pascal]How to use Linux libraries?

Marco van de Voort marcov at stack.nl
Sat Jul 26 11:45:10 CEST 2003

> to
> > use them in the same manner, by loading them and talking to them?
> Yes Rainer, .dll and .so are the same. Generally speaking they are files
> that contains code fragments (functions) much like an executable but that
> can be loaded dynamically at runtime.
> To use an .so library you need to load it in your program. Check the FPC
> docs (http://www.freepascal.org/docs-html/prog/progch11.html#x197-19900011)
> Under windows you can use LoadLibrary, GetProcAddress (to load functions)
> and FreeLibrary, these functions are defined in the windows unit.
> Under Linux you have to use dlopen, dlsym, dlclose which are in the shared
> library 'dl'. As far as I know there is no interface to this library but
> they are really easy to setup in your program:

Don't! Use unit dynlibs. (there are some examples in docs/dynlibex)

Dynlibs is basically a very small wrapper that encapsulates this. However
it will avoid quite a few platform dependant ifdef's.
> //taken from the FPC OpenGL package by Sebastian Guenther (?)
> const
>   RTLD_LAZY         = $001;
>   RTLD_NOW          = $002;
> function dlopen(Name: PChar; Flags: LongInt) : Pointer;  extdecl; external
> 'dl';
> function dlsym(Lib: Pointer; Name: PChar) : Pointer;  extdecl; external
> 'dl';
> function dlclose(Lib: Pointer): LongInt;  extdecl; external 'dl'; 

Since e.g. these are exactly the same on BSD, just in lib 'c'.

etc etc.

More information about the fpc-pascal mailing list