Rev 6098 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{dynload}\title{Foreign Function Interface}\usage{dyn.load(libname, local=TRUE, now=TRUE)dyn.unload(libname)is.loaded(symbol)symbol.C(name)symbol.For(name)}\alias{dyn.load}\alias{dyn.unload}\alias{is.loaded}\alias{symbol.C}\alias{symbol.For}\arguments{\item{libname}{a character string giving the pathname to a DLL.}\item{local}{a logical value controlling whether the symbols in the DLL are storedin their own local table and not shared across DLLs,or added to the global symbol table. Whether this has anyeffect is system-dependent.}\item{now}{a logical controlling whether all symbols are resolved (and relocated)immediately the library is loaded or deferred until theyare used. This control is useful for developers testingwhether a library is complete and has all the necessarysymbols and for users to ignore missing symbols.}\item{symbol}{a character string giving a symbol name.}\item{name}{a character string giving either the name of a Cfunction or Fortran subroutine. Fortran names probably need to be givenentirely in lower case (but this may be system-dependent).}}\value{The function \code{dyn.load} is used for its side effect whichlinks the specified shared library to the executing \R image.Calls to \code{.C}, \code{.Fortran} and \code{.External} canthen be used to execute compiled C functions or Fortran subroutinescontained in the library.The function \code{dyn.unload} unlinks the shared library.Functions \code{symbol.C} and \code{symbol.For} map function /subroutine names tothe symbol name in the compiled code: \code{is.loaded} checks if thesymbol name is loaded and so available for use in \code{.C} \dots.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.The \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 many cases.Additionally, on certain platforms and versions of an operatingsystem, certain libraries must have their symbols loaded globally tosuccesfully resolve all symbols.One should be careful of the potential side-effect of using lazyloading via the `now' argument as `FALSE'. If a routine is called thathas a missing symbol, the process will terminate immediately andunsaved session variables will be lost. The intended use is forlibrary developers to call specify a value `TRUE' to check that allsymbols are actually resolved and for regular users to all with`FALSE' so that missing symbols can be ignored and the available onescan be called.The initial motivation for adding these was to avoid such terminationin the \code{_init()} routines of the Java virtual machinelibrary. However, symbols loaded locally may not be (read probably)available to other DLLs. Those added to the global table are availableto all other elements of the application and so can be shared acrosstwo different 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 Solaris2.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}.}\note{The creation of shared libraries and the runtime linking of theminto executing programs is very platform dependent.In recent years there has been some simplification in the processbecause the C subroutine call \code{dlopen} has become the standardfor doing this under UNIX.Under UNIX \code{dyn.load} uses the \code{dlopen} mechanism andshould work on all platforms which support it. On Windows it usesthe standard mechanisms for loading 32-bit DLLs.The original code for loading DLLs in UNIXwas provided by Heiner Schwarte.The compatibility code for HP-UX was provided by Luke Tierney.}\seealso{\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}\keyword{interface}