[fpc-pascal] static linking vs dynamic linking
Marco van de Voort
marcov at stack.nl
Tue Jan 19 14:08:44 CET 2010
In our previous episode, Graeme Geldenhuys said:
> In fpGUI based applications I have always used static link to libraries
> like Xlib or Xft, using the units xlib.pas and xft.pas
> I want to add spellchecker support (from a C library) to one of my
> applications. So what is better, to continue using static linking, or
> rather use dynamic linking (via dynlibs unit)?
> What would be the pros and cons of each?
Static dynamic: (dyn lib statically linked)
- lib<x>.so must be available at compiletime
- searches ldconfig/ld_library_path at runtime for that name.
Dynamic: (dyn lib dlopen'ed)
- Can look for multiple names, but must guess if they are compatible.
- Must guess paths to search. (afaik all current implementations in headers
don't read out ldconfig, and for certain not platform independant)
The latter is very noticable under FreeBSD where /usr/local/lib and in the
past /usr/x11r6/lib weren't searched (while it usually worked fine when
statically dynamically compiled on FreeBSD).
> Only thing with dynamic linking that I can see, is than 'ldd <myapp>'
> doesn't list the spellchecker library. I also believe, using dynamic
> linking under linux binds you to the linux C library.
Using nearly any C lib will bind you to the C library.
More information about the fpc-pascal