Following up on this question here, I am having issues using dyn.load
to load a shared library that is linked to a Rust dylib. I suspect it has something to do with where R is looking for the Rust dylib, but I have not found a way to specify another location than whatever the default is.
From R, I execute the following:
> dyn.load('src/test.so')
And receive 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 do I load a shared library that depends on another shared library?
The documentation for dyn.load
does not specify how to do this.
Update:
Thanks to shepmaster I was able to successfully build and import a shared library in R. The shared library was compiled in C and is itself linked to a Rust library. These were my steps:
- Compile shared Rust library
- Compile shared C library and link to the Rust library using the following command (in Windows as I'm at work 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 the library in R:
> dyn.load("test.dll")
> is.loaded("triple")
[1] TRUE
> .Call("triple", as.integer(32))
The triple is 96