[R] dyn.load

Prof Brian D Ripley ripley at stats.ox.ac.uk
Tue Sep 14 20:25:28 CEST 1999


On Tue, 14 Sep 1999, Mestivier Denis wrote:

> Hello,
> 
> I have a probleme with the dynamic loading. I make
> two librairies "myfct.so" and "otherfct.so", where
> "myfct.so" is calling functions of "otherfct.so",
> and I want dyn.load() each of it,  without generating
> a unique librarie. For exemple :
> 
> myfct.c :
> 
> void myfct(double *x, double *y)
> {
>  otherfct(x);
>  *y=(*x)+1.0;
> }
> 
> myoth.c :
> 
> void otherfct( double *x )
> {
>  *x=99.;
> }
> 
> I create the two libraries as following :
> 
> ~/R/testR$ R SHLIB myfct.c
> gcc -g -O2 -fpic -I/usr/local/lib/R/include -c myfct.c -o myfct.o
> ld -shared -o myfct.so myfct.o
> ~/R/testR$ R SHLIB myother.c
> gcc -g -O2 -fpic -I/usr/local/lib/R/include -c myother.c -o myother.o
> ld -shared -o myother.so myother.o
> 
> Then, when I am running R :
> 
> > dyn.load("myother.so")
> > dyn.load("myfct.so")
> > x_5
> > y_7
> > is.loaded(symbol.C("myfct"))
> [1] TRUE
> > is.loaded(symbol.C("otherfct"))
> [1] TRUE
> > .C("myfct",x,y)
> /usr/local/lib/R/bin/R.binary: error in loading shared libraries
> /home/mestiv/R/testR/myfct.so: undefined symbol: otherfct
> 
> What is my error ?

What is your platform?  I can give you an answer for Solaris. R uses
RTLD_LOCAL in its call to dlopen, and that says

     RTLD_LOCAL        The  object's  globals  symbols  are  only
                       available for the relocation processing of
                       other  objects  that  comprise  the   same
                       group.

In other words, symbols in myother.so are only available to shared
libraries linked with it, not others.

Two solutions are:

(1) Make myfct.so a dependence of myother.so so it gets linked in the same
group.

(2) Use R-release, that has a local=TRUE flag on dyn.open.


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