Go to the first, previous, next, last section, table of contents.


Finding the correct name to dlopen

After a library has been linked with `-export-dynamic', it can be dlopened. Unfortunately, because of the variation in library names, your package needs to determine the correct file to dlopen.

Dlname mode (see section Dlname mode) was designed for this purpose. It returns the name that should be given as the first argument to a dlopen(3) function call.

For example, on NetBSD 1.2:

burger$ libtool --mode=dlname libhello.la
libhello.so.3.12
burger$

The trick is in finding a way to hardcode this name into your program at compilation time, so that it opens the correct library.

An alternative implementation that avoids hardcoding is to determine the name at runtime, by finding the installed `.la' file, and searching it for the following lines:

# The name that we can dlopen(3).
dlname='dlname'

If dlname is empty, then the library cannot be dlopened. Otherwise, it gives the dlname of the library. So, if the library was installed as `/usr/local/lib/libhello.la', and the dlname was `libhello.so.3', then `/usr/local/lib/libhello.so.3' should be dlopened.

If your program uses this approach, then it should search the directories listed in the LD_LIBRARY_PATH(8) environment variable, as well as the directory where libraries will eventually be installed. Searching this variable (or equivalent) will guarantee that your program can find its dlopened modules, even before installation, provided you have linked them using libtool.


Go to the first, previous, next, last section, table of contents.