dlopen

dlopen — loads a dynamic library from a file.

Syntax

dlopen (filename flags)

		

Arguments

filename

The name of the file to open, as a string. If no absolute path is given, the file is searched for in the user's LD_LIBRARY path, the /etc/ld.so.cache list of libraries, and the /usr/lib/ directory.

flags

Must be either RTLD_LAZY or RTLD_NOW, optionally OR'ed with RTLD_GLOBAL.

    RTLD_LAZY  causes undefined symbols to be resolved as the dynamic library code executes.

    RTLD_NOW forces undefined symbols to be resolved before dlopen returns, otherwise dlopen fails.

    RTLD_GLOBAL makes any external symbols defined in the library available to subsequently loaded libraries.

Returns

An integer "handle" if successful, else 0.

Description

This function is a wrapper for the dlopen shell command. It loads a dynamic library from the file and returns a "handle", which is an integer uniquely associated with the file for this application. The same handle is returned each time the same library is opened, and the dl library counts the number of links created for each handle.

If the library exports a routine named _init, that will be executed before dlopen returns.

Example

Gamma> dlopen("libform.so",RTLD_LAZY|RTLD_GLOBAL);
134936808
Gamma> dlopen("libconsole.so",RTLD_NOW);
0
Gamma> dlopen("libconsole.so",RTLD_LAZY);
134935848
Gamma> dlopen("libconsole.so",RTLD_LAZY);
134935848
		

See Also

dlclose