[Rd] dyn.load and function calls without 'PACKAGE' argument

Jeffrey J. Hallman m1jjh00 at frb.gov
Fri Dec 8 21:40:41 CET 2006


Duncan Temple Lang <duncan at wald.ucdavis.edu> wrote:

  dtl> jhallman at frb.gov wrote:
  >> dyn.load("/opt/fame/timeiq/lib/linux_x86/libjchli.so", local = F)
  >> library.dynam("fame", package = "fame")
  >> The code in fame.so uses functions found in libjchli.so, making the
  >> 'local = F' argument in dyn.load() necessary. 

  dtl> Well, that is one approach.
  dtl> A more  regular and in most senses "better" approach is to
  dtl> have your fame.so link against libjchli.so when creating
  dtl> the fame.so DLL/SO.  Then you don't have to pollute the
  dtl> global symbol table for the process with libjchli.so
  dtl> and you can use the PACKAGE argument.

Will that work?  Some of the functions in libjchli.so get called
directly via .C().  How would linking fame.so against libjchli.so help
when fame.so doesn't know what functions in libjchli.so I am going to
call?  Perhaps I don't understand how linking works. Please feel free to
enlighten me.

  dtl> That said, the PACKAGE argument is not necessary if you use
  dtl> a NAMESPACE file for the package.
  dtl> Load the fame.so with useDynLib() in the NAMESPACE file
  dtl> and not library.dynam()

As I understand it, useDynLib(fame) is actually a directive that results
in fame.so being loaded via library.dynam(). I am using a NAMESPACE, so
I will try your advice and thank you for it. 

  dtl> And if you explicitly list the routines you want to use
  dtl> in the useDynLib() call, you can refer to them as
  dtl>   .Call(foo, ...)

  dtl> with no quotes, no PACKAGE and you will be able to handle
  dtl> multiple versions and provide aliases for the routine names.

What if I don't explicitly list the routines?  Many of the routines are
only compiled in for Unix, not Windows.  Is there a way to use a
different useDynLib() directive depending on the operating system?

Jeff



More information about the R-devel mailing list