Following this question here , I am having problems using dyn.load to load a shared library related to Rust dylib. I suspect this has something to do with where R searches for Rul dylib, but I have not found a way to specify a different location than what is by default.
From R, I do the following:
> dyn.load('src/test.so')
And get this error message:
Error in dyn.load("src/test.so") : unable to load shared object '/Users/Zelazny7/r-dev/rustr/src/test.so': dlopen(/Users/Zelazny7/r-dev/rustr/src/test.so, 6): Library not loaded: libglue.dylib Referenced from: /Users/Zelazny7/r-dev/rustr/src/test.so Reason: image not found
How to load a shared library that depends on another shared library?
The documentation for dyn.load does not indicate how to do this.
Update:
Thanks to shepmaster, I was able to successfully create and import the shared library into R. The shared library was compiled in C and itself linked to the Rust library. These were my steps:
- Compile a common Rust library.
- Compile the common C library and the link to the Rust library with the following command (on Windows when I am this morning)
My directory contents:
C:\Users\gravesee\test>ls rglue.dll rglue.rs rustr.c treble.h
Compiling the final shared library:
gcc -shared -m64 -I"C:\Program Files\R\R-3.2.0\include" rustr.c -L"C:\Program Files\R\R-3.2.0\bin\x64" -lR -L. -lrglue -o test.dll
Loading library in R:
> dyn.load("test.dll") > is.loaded("triple") [1] TRUE > .Call("triple", as.integer(32)) The triple is 96
r shared-libraries rust
Zelazny7
source share