Dynamically linked libraries (xxx.so file in Unix family, xxx.dll file in Windows) can be loaded by the following SML# structure:
structure DynamicLink : sig val dlclose : unit ptr -> unit val dlopen : string -> unit ptr val dlsym : unit ptr * string -> unit ptr end
- dlopen(path) opens the given file path path, and returns a handle pointer (of type unit ptr） to it. If open fails then the function raise SysErr exception.
- dlsym(ptr, s) searches the function having name s in the library pointed by the handle ptr, and returns a pointer to the function.
- dlclose(ptr) closes the library file pointed by ptr.
Library name resolution is platform dependednt. In a Unix family OS, SML# uses 'dlopen' and 'dlsym' library functions, which consult the environment variable LD_LIBRARY_PATH for library path.
DynmicLink is one of FFI Libraries, which contain several other useful utility modules.