Class DynamicLinkLoader



  • public class DynamicLinkLoader
    extends java.lang.Object
    Native bindings to .
    • Method Detail

      • dlopen

        public static long dlopen(java.nio.ByteBuffer path,
                                  int mode)
        
        public static long dlopen(java.lang.CharSequence path,
                                  int mode)
        
        Loads and links a dynamic library or bundle.

        This function examines the Mach-O file specified by path. If the image is compatible with the current process and has not already been loaded into the process, the image is loaded and linked. If the image contains initializer functions, they are executed before this function returns.

        Subsequent calls to dlopen to load the same image return the same handle, but the internal reference count for the handle is incremented. Therefore, all dlopen calls must be balanced with DynamicLinkLoader.dlclose(long) calls.

        For efficiency, the DynamicLinkLoader.RTLD_LAZY binding mode is preferred over DynamicLinkLoader.RTLD_NOW. However, using DynamicLinkLoader.RTLD_NOW ensures that any undefined symbols are discovered during the call to dlopen.

        The dynamic loader looks in the paths specified by a set of environment variables, and in the process's current directory, when it searches for a library. These paths are called dynamic loader search paths. The environment variables are LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, and DYLD_FALLBACK_LIBRARY_PATH. The default value of DYLD_FALLBACK_LIBRARY_PATH (used when this variable is not set), is $HOME/lib;/usr/local/lib;/usr/lib.

        The order in which the search paths are searched depends on whether path is a filename (it does not contain a slash) or a pathname (it contains at least one slash).

        When path is a filename, the dynamic loader searches for the library in the search paths in the following order:

        • $LD_LIBRARY_PATH
        • $DYLD_LIBRARY_PATH
        • The process's working directory
        • $DYLD_FALLBACK_LIBRARY_PATH

        When path is a pathname, the dynamic loader searches for the library in the search paths in the following order:

        • $DYLD_LIBRARY_PATH
        • The given pathname
        • $DYLD_FALLBACK_LIBRARY_PATH using the filename
        Parameters:
        path - path to the image to open
        mode - specifies when the loaded image's external symbols are bound to their definitions in dependent libraries (lazy or at load time) and the visibility of the image's exported symbols (global or local). The value of this parameter is made up by ORing one binding behavior value with one visibility specification value.

        The following values specify the binding behavior:

        The following values specify external symbol visibility:

      • dlclose

        public static int dlclose(long handle)
        Closes a dynamic library or bundle.

        This function decreases the reference count of the image referenced by handle. When the reference count for handle becomes 0, the termination routines in the image are called, and the image is removed from the address space of the current process. After that point, handle is rendered invalid.

        Parameters:
        handle - a handle obtained through a call to DynamicLinkLoader.dlopen(java.nio.ByteBuffer, int).