What is UNIX

The Dynamic Linking Extension

A White Paper from the X/Open Base Working Group.

Version 1 Last update March 12 1997.


This white paper gives a brief outline of the Dynamic Linking Extension put forward by the Aspen group.

This paper is part of a series of brief papers describing new and changed features in the UNIX specification.

1.1 What is the Dynamic Linking Extension

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.

1.2 The Benefits of Dynamic Linking

Use of dynamic linking allows several benefits for application developers:

1.3 Functional Overview

dlopen() - gain access to an executable object file

This 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() object

This 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 other technical papers.

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.