A White Paper from the X/Open Base Working Group.
Version 1 Last update March 12 1997.
Abstract
The Dynamic linking extension that came out of the Aspen group comprises a set of four routines and a header file to provide a portable API for manipulation of an implementation defined class of files, which typically could be shared libraries. These routines are based on those introduced in UNIX System V Release 4.
Use of dynamic linking allows several benefits for application developers:
dlopen()
- gain access to an executable object fileThis routine can be used to attach a shared object during a process lifetime, for example
#include <dlfcn.h>
void *mylib;
mylib = dlopen ("mylib.so.1", RTLD_LAZY);
dlsym()
- obtain address of a symbol from dlopen() objectThis routine can be used to obtain the address of a symbol within an object, for example
int (*myptr) ();
myptr = (int (*) ()) dlsym (mylib, "mysymname");
and then, it is possible to manipulate the data or function by a dereference to the address:
int foobar;
foobar = (*myptr) ();
dlclose()
- close a dlopen() object
This function is used to inform the system that the object attached
by a previous call to dlopen()
is no longer needed
by the application, for example:
int foo;
foo = dlcose( mylib );
dlerror()
- get diagnostic information
This function is used to find out diagnostic information if any
of the other dynamic linking routines returned an error.
A call to dlerror()
will then return a string
describing the error, for example:
char *errstr;
errstr = dlerror();
One point to note about this routine, is that it is not thread safe, since the string may reside in a static area which is overwrittem whenever an error occurs.
Read or download the complete Single UNIX Specification from http://www.UNIX-systems.org/go/unix.
Copyright © 1997-1998 The Open Group
UNIX is a registered trademark of The Open Group.