[LCP]Dynamic libraries and plugins

Vincent Penquerc'h Vincent.Penquerch at artworks.co.uk
Mon Jun 24 20:28:05 UTC 2002


> If I use a
> function from a library that's not compiled INTO my program, 
> how does my
> program  use of it?  After all, if this is the case, then it 
> would have
> to lookup a specific library from disk.  So is there some

A program is linked to the shared (dynamic) libraries it
uses (.so files). The .so files are just not included in
the final elf (or whatever exe format you happen to use).
At load time (hence dynamic), the necessary shared libs
are looked up (you can find out what foo needs by running
"ldd foo") and loaded if not already. If several programs
need it, they all have read/execute access on the
appropriate pages, so the lib is loaded only once in
memory (hence shared).
The load code does some load time linking, which I suspect
(but am not sure) boils down to replacing in the code the
addresses of jumps to the lib routines by the ones which
corresponds to the address the shared lib is loaded at.

You can do this by hand if you want to, but you'll have to
use function pointers: lookup dlopen, dlsym and friends.
This is how you can load a library at runtime. Handy for
things like drivers, or user customization libs.

-- 
Vincent Penquerc'h 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.linux.org.au/pipermail/linuxcprogramming/attachments/20020624/16b3780b/attachment.htm 


More information about the linuxCprogramming mailing list