[Rd] reusing external functions across libs

Prof Brian D Ripley ripley@stats.ox.ac.uk
Wed, 6 Sep 2000 09:30:37 +0100 (BST)

On Wed, 6 Sep 2000, Albrecht Gebhardt wrote:

> ... well, I found (at least) one solution:
> > dyn.load("so1.so",now=F)
> > dyn.load("so2.so",local=F)
> > .C("func1",as.double(c(1,2,3)),as.integer(3))
> in func1
> in func2
>  [1]
> back in func1
> [[1]]
> [1] 2 4 6
> [[2]]
> [1] 3
> > 
> but the question remains:
> What is the best way to share common C/Fortran sources across R libraries?
> How should I implement the above solution in the libraries? What are the
> side effects? Is it really portable (win32?)? 

It is not portable.  You will not even be able to make both shared
objects on some systems, including AIX and Windows, as they need to know
where the symbols are going to be satisfied.  And those flags (especially
local=F) do not always work (which is why this worked on OSF4, I think).

The best way that I know of is to put shared code in a shared library, and
link so?.so against that.  The only potential problem is putting the
common library somewhere it will be found at run time if it is a shared
library/DLL, so I would use a static library unless the code was large
(like all of LAPACK).  (This is particularly a problem on Windows,
where the rules for finding DLLs differ by Windows version.)

Brian D. Ripley,                  ripley@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-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