Go to the first, previous, next, last section, table of contents.
The libltdl API is similar to the dlopen interface of Solaris and Linux, which is very simple but powerful.
To use libltdl in your program you have to include the header file `ltdl.h':
#include <ltdl.h>
The last release of libltdl used some symbols that violated the POSIX namespace conventions. These symbols are now deprecated, and have been replaced by those described here. If you have code that relies on the old deprecated symbol names, defining `LT_NON_POSIX_NAMESPACE' before you include `ltdl.h' provides conversion macros. Whichever set of symbols you use, the new api is not binary compatible with the last, so you will need to recompile your application in order to use this version of libltdl.
Note that libltdl is not threadsafe, i.e. a multithreaded application
has to use a mutex for libltdl. It was reported that GNU/Linux's glibc
2.0's dlopen
with `RTLD_LAZY' (which libltdl uses by
default) is not thread-safe, but this problem is supposed to be fixed in
glibc 2.1. On the other hand, `RTLD_NOW' was reported to introduce
problems in multi-threaded applications on FreeBSD. Working around
these problems is left as an exercise for the reader; contributions are
certainly welcome.
The following types are defined in `ltdl.h':
lt_ptr
is a generic pointer.
lt_dlhandle
is a module "handle".
Every lt_dlopened module has a handle associated with it.
lt_dlsymlist
is a symbol list for dlpreopened modules.
This structure is described in see section Dlpreopening.
libltdl provides the following functions:
lt_dlinit
has been successfully called.
Return 0 on success, otherwise the number of errors.
lt_dlopen
is able to open libtool dynamic
modules, preloaded static modules, the program itself and
native dynamic libraries.
Unresolved symbols in the module are resolved using its dependency
libraries (not implemented yet) and previously dlopened modules. If the
executable using this module was linked with the -export-dynamic
flag, then the global symbols in the executable will also be used to
resolve references in the module.
If filename is NULL
and the program was linked with
-export-dynamic
or -dlopen self
, lt_dlopen
will
return a handle for the program itself, which can be used to access its
symbols.
If libltdl cannot find the library and the file name filename does not have a directory component it will additionally search in the following search paths for the module (in the order as follows):
lt_dlsetsearchpath
and lt_dladdsearchdir
.
Each search path must be a colon-separated list of absolute directories,
for example, "/usr/lib/mypkg:/lib/foo"
.
If the same module is loaded several times, the same handle is returned.
If lt_dlopen
fails for any reason, it returns NULL
.
lt_dlopen
, except that it tries to append
different file name extensions to the file name.
If the file with the file name filename cannot be found
libltdl tries to append the following extensions:
This lookup strategy was designed to allow programs that don't
have knowledge about native dynamic libraries naming conventions
to be able to dlopen
such libraries as well as libtool modules
transparently.
NULL
is returned.
NULL
if no errors have occurred since initialization
or since it was last called.
NULL
, then all previously registered
symbol lists, except the list set by lt_dlpreload_default
,
are deleted. Return 0 on success.
lt_dlpreload
. Note that this function does
not require libltdl to be initialized using lt_dlinit
and
can be used in the program to register the default preloaded modules.
Instead of calling this function directly, most programs will use the
macro LTDL_SET_PRELOADED_SYMBOLS
.
Return 0 on success.
#include <ltdl.h> int main() { /* ... */ LTDL_SET_PRELOADED_SYMBOLS(); /* ... */ }
If you use `lt_dlopen (NULL)' to get a handle for the running binary, that handle will always be marked as resident, and consequently cannot be successfully `lt_dlclose'd.
lt_dlerror
.
malloc
and free
, by default,
but you can set them to any other functions that provides equivalent
functionality. However, you must not modify their values after calling
any libltdl function other than lt_dlpreopen_default
or the macro
LTDL_SET_PRELOADED_SYMBOLS
.
Go to the first, previous, next, last section, table of contents.