From bolker@zoo.ufl.edu  Tue Mar 12 15:00:28 2002
From: bolker@zoo.ufl.edu (Ben Bolker)
Date: Tue, 12 Mar 2002 10:00:28 -0500 (EST)
Subject: [Rd] using R API in dynamically loaded code?
Message-ID: <Pine.LNX.4.30.0203120947030.3612-100000@bolker.zoo.ufl.edu>


  I'm probably missing something very basic here, but:

  I've written some C code that I load into R dynamically.  In the course
of this C code, I generate some multinomial random deviates.  I initially
used the publically available "randlib"  library, which also implements
its own random number generator and binomial deviates (which are used to
generate the multinomial deviates).  For parsimony and for licensing
reasons (the randlib licensing is not entirely clear, but there's some
wording about ACM algorithms that contradict GPL), I thought I should pull
out just the multinomial generator from randlib and use it along with
rbinom calls from the R API. Following the R-exts document, I included
<R.h> in my code, used GetRNGstate/PutRNGstate to initialize the random
number generator, and called rbinom from within my code.
  When using "R CMD check" to build the library and test it, the dynamic
library (turtle.so) fails to load, complaining that rbinom is an
unresolved symbol.  If I force now=FALSE in the dyn.lib call (which seemed
like it *might* solve the problem), I get a "relocation error" when trying
to load the library instead.
  How do I indicate that these symbols within the library refer to
functions that should be called from R?  Am I simply on the wrong track?

  I can provide a stripped-down example if that will clarify things.

  thanks,
    Ben Bolker

-- 
318 Carr Hall                                bolker@zoo.ufl.edu
Zoology Department, University of Florida    http://www.zoo.ufl.edu/bolker
Box 118525                                   (ph)  352-392-5697
Gainesville, FL 32611-8525                   (fax) 352-392-3704

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] using R API in dynamically loaded code?
Ben Bolker