[R] Shared libraries for use with R

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jan 18 22:00:00 CET 2002


On Fri, 18 Jan 2002, Giovanni Petris wrote:

>
> I am moving my first steps in writing and compiling C code and calling
> it from R. (I am also new to shared libraries...) My
> problem is that my C code uses a C function contained in
> another library (".a", not ".so" - is that the problem?).
>
> This is how I compile the file with the functions I want to call from R:
>
> cd /export/home/gpetris/
> R SHLIB tryit.c
> cc -I/export/home/share/R/R-1.4.0/lib/R/include "-I/export/home/gpetris/C" -I/usr/local/include -I/export/home/share/include   -KPIC  -xO5 -dalign -xlic_lib=sunperf -c tryit.c -o tryit.o
> cc -G  -o tryit.so tryit.o "-L/export/home/gpetris/lib/SUN/32bit -lutil -lrand" -L/usr/local/lib -L/export/home/share/lib
>
> Compilation finished at Fri Jan 18 12:45:20
>
> So far, so good. But when I dyn.load it in R:

Solaris, I presume from the flags, but *please* tell us enough background
information.

> > dyn.load("tryit.so")
> Error in dyn.load(x, as.logical(local), as.logical(now)) :
> 	unable to load shared library "/export/home/gpetris/tryit.so":
>   ld.so.1: /export/home/share/R/R-1.4.0/lib/R/bin/R.bin: fatal: relocation error: file /export/home/gpetris/tryit.so: symbol dmatrix: referenced symbol not found
>
> The function dmatrix is contained in the object file nrutil.o in
> the library /export/home/gpetris/lib/SUN/32bit/libutil.a
> I was hoping that the flags given to R SHLIB could take care of that,
> but apparently I was wrong...

Try nm -pg tryit.so and ldd tryit.so.  The linker will use a shared
version of libutil if one exists, and then you would need a -R flag.

I am also not sure why you have quotes around parts of the cc lines: I
think you have been quoting in Makevars when you should not be.

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