[Lazarus] RE : Dynamic loading of a custom sqlite library

Ludo Brands ludo.brands at free.fr
Sat Jun 11 11:34:58 CEST 2011


The solution you propose to avoid the effect of loading dynamically a
library which has already been marked for loading by the linker seems quite
dangerous. Suppose the unit that caused the linker to include the library
(call it lib1) executes some initialization routines. These will run in
lib1. Now you load dynamically the same lib (lib2). From now on all calls to
the library functions are executed in lib2. At the end the unit that used
lib1 could execute some finalization routines. But this time they run in
lib2. Unless you lib2 unloaded completely before the unit finalization. I
guess there could be other situations where this causes problems. Possibly
everything is fine for sqlite3 but documenting it as a general solution is
IMHO not correct.

Why not check at run-time if the library is already loaded: 
Mod:=dlopen(nil,RTLD_LAZY);
libloaded:=assigned(dlsym(Mod,'symbol in lib'));
dlclose(Mod);

Ludo


> -----Message d'origine-----
> De : zeljko [mailto:zeljko at holobit.net] 
> Envoyé : samedi 11 juin 2011 09:11
> À : Lazarus mailing list
> Objet : Re: [Lazarus] Dynamic loading of a custom sqlite library
> 
> 
> On Friday 10 of June 2011 10:22:34 Max Vlasov wrote:
> >
> > Looks like it's linux-only patch introduced at around 2004
> >   http://sourceware.org/ml/libc-hacker/2004-09/msg00083.html
> > so was not a good idea to update rtl\unix\dl.pp :)
> 
> But would be ok to add it to documentation of dynlibs, that 
> someone can use 
> that flag under linux if have similar problem. I had same 
> problem with sqlite3 
> and double installation of it under fedora 1.system one 
> 2.xulrunner one, 
> always had crashes if firefox is started before I use my app. 
> With that flag 
> it's fixed.
> 
> zeljko
> 
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
> 





More information about the Lazarus mailing list