Sign in Join

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

Mailing lists / fpc-pascal / 2010-01

static linking vs dynamic linking

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

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?

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. The only other pro for dynamic linking i can see, is that if the spellchecker library is not available, only spellcheck support will be disabled and the application can still continue running. I guess this would be the deciding factor - is it a requirement or an optional extra having spellchecker support.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/
Marco van de Voort
to Graeme Geldenhuys

In our previous episode, Graeme Geldenhuys said:

Show quoted text 8 lines
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.