Rev 8710 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{dyn.load}\alias{dyn.load}\alias{dyn.unload}\alias{is.loaded}\alias{symbol.C}\alias{symbol.For}\title{Foreign Function Interface}\description{Load or unload shared libraries, and test whether a C function orFortran subroutine is available.}\usage{dyn.load(libname, local = TRUE, now = TRUE)dyn.unload(libname)is.loaded(symbol)symbol.C(name)symbol.For(name)}\arguments{\item{libname}{a character string giving the pathname to a DLL.}\item{local}{a logical value controlling whether the symbols in theDLL are stored in their own local table and not shared across DLLs,or added to the global symbol table. Whether this has any effect issystem-dependent.#ifdef windowsIt is ignored on Windows.#endif}\item{now}{a logical controlling whether all symbols are resolved (andrelocated) immediately the library is loaded or deferred until theyare used. This control is useful for developers testing whether alibrary is complete and has all the necessary symbols and for usersto ignore missing symbols. Whether this has any effect is system-dependent.#ifdef windowsIt is ignored on Windows.#endif}\item{symbol}{a character string giving a symbol name.}\item{name}{a character string giving either the name of a C functionor Fortran subroutine. Fortran names probably need to be givenentirely in lower case (but this may be system-dependent).}}\details{The additional arguments to \code{dyn.load} mirror the differentaspects of the mode argument to the dlopen() routine on UNIXsystems. They are available so that users can exercise greater controlover the loading process for an individual library. In general, thedefaults values are appropriate and one should override them only ifthere is good reason and you understand the implications.#ifdef unixThe \code{local} argument allows one to control whether the symbols inthe DLL being attached are visible to other DLLs. While maintainingthe symbols in their own namespace is good practice, the ability toshare symbols across related ``chapters'' is useful in manycases. Additionally, on certain platforms and versions of anoperating system, certain libraries must have their symbols loadedglobally to successfully resolve all symbols.One should be careful of the potential side-effect of using lazyloading via the `now' argument as \code{FALSE}. If a routine iscalled that has a missing symbol, the process will terminateimmediately and unsaved session variables will be lost. The intendeduse is for library developers to call specify a value \code{TRUE} tocheck that all symbols are actually resolved and for regular users toall with \code{FALSE} so that missing symbols can be ignored and theavailable ones can be called.The initial motivation for adding these was to avoid such terminationin the \code{_init()} routines of the Java virtual machine library.However, symbols loaded locally may not be (read probably) availableto other DLLs. Those added to the global table are available to allother elements of the application and so can be shared across twodifferent DLLs.Some systems do not provide (explicit) support for local/global andlazy/eager symbol resolution. This can be the source of subtle bugs.One can arrange to have warning messages emitted when unsupportedoptions are used. This is done by setting either of the options\code{verbose} or \code{warn} to be non-zero via the\code{\link{options}} function. Currently, we know of only 2platforms that do not provide a value for local load (RTLD\_LOCAL).These are IRIX6.4 and unpatched versions of Solaris 2.5.1.There is a short discussion of these additional arguments with someexample code available at\url{http://cm.bell-labs.com/stat/duncan/R/dynload}.#endif}\value{The function \code{dyn.load} is used for its side effect which linksthe specified shared library to the executing \R image. Calls to\code{.C}, \code{.Fortran} and \code{.External} can then be used toexecute compiled C functions or Fortran subroutines contained in thelibrary.The function \code{dyn.unload} unlinks the shared library.Functions \code{symbol.C} and \code{symbol.For} map function orsubroutine names to the symbol name in the compiled code:\code{is.loaded} checks if the symbol name is loaded and henceavailable for use in \code{.C} or \code{.Fortran}.}\note{The creation of shared libraries and the runtime linking of them intoexecuting programs is very platform dependent. In recent years therehas been some simplification in the process because the C subroutinecall \code{dlopen} has become the standard for doing this under UNIX.Under UNIX \code{dyn.load} uses the \code{dlopen} mechanism and shouldwork on all platforms which support it. On Windows it uses thestandard mechanisms for loading 32-bit DLLs.The original code for loading DLLs in UNIX was provided by HeinerSchwarte. The compatibility code for HP-UX was provided by LukeTierney.}\seealso{\code{\link{library.dynam}} to be used inside a package's\code{\link{.First.lib}} initialization.\code{\link{.C}},\code{\link{.Fortran}},\code{\link{.External}},\code{\link{.Call}}.}\examples{is.loaded(symbol.For("hcass2")) #-> probably FALSElibrary(mva)is.loaded(symbol.For("hcass2")) #-> TRUE\testonly{detach("package:mva")}}\keyword{interface}