[R] R/C interface

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Wed Jul 17 14:24:55 CEST 2002


On Wed, 17 Jul 2002 estuart at fas.harvard.edu wrote:

> Hi,
> I am trying to use the R/C interface on a Unix system that unfortunately does
> not have the gnu C compiler and am having trouble accessing the math functions
> from math.h.
>
> To compile a C program with math functions on this system, the following
> command is used (and the order is important: the /usr/lib/libm.a statement must
> come at the end of the command):
> "cc program.c /usr/lib/libm.a"

What Unix system is this?  It would be unusual not to use a shared libm if
there is one at all.  (If this is really a Unix(TM) system then you should
not need to worry about libm as R's configuration will handle it
automatically.)

I think what you actually want to use is

cc -c program.c
cc -o program program.o -lm

However, to use C programs with R you need to make a shared library, not
an executable.  You shouldn't need to link the shared library against libm
(since R.bin itself would be linked against libm.so), but if you do, you
can add "-lm" to SHLIB_LIBADD.

> I am having trouble getting R to compile the C programs with this extra command
> (/usr/lib/libm.a).  I have tried the CFLAGS option, and have looked at the
> scripts for the COMPILE and SHLIB commands but have not seen anything obvious
> (and I am not very familiar with Unix and C in general).
>
> Is there some way I can get R to use this when it does the C compiling in R CMD
> COMPILE and R CMD SHLIB?

If you still have problems, please send us details of the system and the
output from R CMD SHLIB (and from dyn.load if that fails).  We will then
be able to ask more specific diagnostic questions.

-- 
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