Skip to content

How to find system directory to shared library?

5 messages · Kasper Daniel Hansen, Simon Urbanek, cstrato

#
Dear all

In my package I need to get the path to the shared library "mypackage.so".
Currently, I use the following code:

   mydir <- system.file(package="mypackage")
   mylib <- paste(mydir, "/libs/mypackage.so", sep="")

This did work with FC4 running R-2.4.1 and on my Intel-Mac running the
development version of R-2.5.0, which I did compile from source.

However, now I have downloaded and installed R-2.5.0.dmg and get an
error since the shared library is now located in: "/libs/i386/mypackage.so"
So I changed the code to:

   mydir <- paste(system.file(package="mypackage"),  "libs", sep="/");
   if (list.files(mydir) == "mypackage.so") {
      mylib  <- paste(mydir, "mypackage.so", sep="/");
   } else {
      mylib  <- paste(mydir, list.files(mydir), "mypackage.so", sep="/");
   }

This works since there is only one subdirectory "i386", but not if there
are "i386" and "ppc" subdirectories.

Sorrowly, the following does not work:
   system.file("mypackage.so", package = "mypackage")

My question is, is there a better way to find the path to the shared 
library?

Best regards
Christian
_._._._._._._._._._._._._._._._
C.h.i.s.t.i.a.n S.t.r.a.t.o.w.a
V.i.e.n.n.a       A.u.s.t.r.i.a
_._._._._._._._._._._._._._._._
#
On May 12, 2007, at 12:43 PM, cstrato wrote:

            
Eh, why do you need to do so? I am not saying there could not be use  
cases, but most standard uses should not need to do this.

Kasper
#
On May 12, 2007, at 3:43 PM, cstrato wrote:

            
This won't work on any multi-arch R (like any Mac version on CRAN)  
and neither on Windows. In most case you shouldn't be accessing it  
directly anyway (use library.dynam if you want to load it). If you  
really want the path to another package's dylib, you can use  
something like

pkg = "mypackage"
mylib = system.file("libs", .Platform$r_arch, paste(pkg, .Platform 
$dynlib.ext, sep=''), package=pkg)

Cheers,
Simon
#
Dear Simon

Thank you very much, this is exactly what I needed, great.

Best regards
Christian
Simon Urbanek wrote:
#
Kasper Daniel Hansen wrote:
Since I am calling another program from within R which needs to know the 
path to my shared lib.
Christian