From ripley at stats.ox.ac.uk  Mon Jul 30 22:36:06 2012
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon, 30 Jul 2012 21:36:06 +0100
Subject: [Rd] Shared routines in a dynamic library.
In-Reply-To: <OF6269363E.841F3B79-ON86257A4B.004A38BE-86257A4B.004BCF4D@usgs.gov>
References: <CABdHhvFstF51xCxPHLZssh0A6ORH9PfVi2W=ZyonrF=X4XxRPQ@mail.gmail.com>
	<E66794E69CFDE04D9A70842786030B932DEEE1@PA-MBX01.na.tibco.com>
	<OF6269363E.841F3B79-ON86257A4B.004A38BE-86257A4B.004BCF4D@usgs.gov>
Message-ID: <5016F036.8010102@stats.ox.ac.uk>

On 30/07/2012 14:48, David L Lorenz wrote:
> All,
>    I have a question about referring to a subroutine that is in a dynamic
> library other than the one in my current package.
> Let's say that I have a package foo and it has some FORTRAN code that
> contains the subroutines foo1 and foocommon. The package foo has an R
> function that calls foo1 and foocommon is a subroutine that is called from
> foo1.
> And, I have another package called bar which also has some FORTRAN code
> that contains the subrouting bar1. But bar1 also calls foocommon. The bar
> package is distinctly different from foo, but would require foo (even if
> the FORTRAN code did not have the common subroutine).
>
>    I can think of a few ways to resolve this.
> 1. Place a copy of foocommon.f into the shared library for bar.
> 2. Put all of the FORTRAN code into the foo package and just rely on the R
> code in bar to call the code that it needs.
> 3. Refer to the shared library in the bar package. I assume that I'd do
> this in the NAMESPACE file using useDynLib(foo) in addition to
> useDynLib(bar), but I found no reference to it in Writing R extensions.
>    Is there a recommended way to solve this issue? Thanks.

See 
http://cran.r-project.org/doc/manuals/R-exts.html#Linking-to-other-packages 
.  It is the main recommendation (and none of the above).

If bar loads foo, you can access things in foo's DLL by e.g.
.C("bah", PACKAGE="foo").  foo's DLL must be loaded so (3.) is not 
relevant.   But that is dangerous (foo might change) and will be noted 
by R CMD check.


-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] Shared routines in a dynamic library.
Prof Brian Ripley