[R] using fmod in C code to be loaded into R

Prof Brian D Ripley ripley at stats.ox.ac.uk
Tue Feb 27 08:14:46 CET 2001


On Mon, 26 Feb 2001, Faheem Mitha wrote:

> Dear People,
>
> I wrote the following bit of C code and (along with other bits) called it
> mycode.c, and compiled the file into a shared library to load into R,
> using R CMD SHLIB mycode.c. This was Ok, but when I tried to load this
> into R using dyn.load("mycode.so") I got the error
>
> > dyn.load("mycode.so")
> Error in dyn.load(x, as.logical(local), as.logical(now)) :
> 	unable to load shared library "/home/faheem/research/mycode.so":
>   /home/faheem/research/mycode.so: undefined symbol: Rf_fmod
>
> "Writing R extension" says this function is available as an entry point.
> I have only a vague undertstanding of entry points, but I understand this
> to mean that if I am going to load the compiled code into R to be called
> from R, then I can stick such a function in my code, and provided I have
> the header Rmath.h included, everything will be Ok.
>
> This works with rnorm, for example. What am I doing wrong here?

Nothing. The person who added it to the list in R-exts didn't check
it was included in the binary.  There is C code to do this, but as it is
unused in R itself, it is not included in the binary.

fmod is a standard C function of two arguments, so I have no idea why R has
an unused entry point aliased to fmod with one argument.

I suggest you #undef fmod after the headers, and use the standard form
in your code.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list