[R-SIG-Mac] link a shared library of a r-package

Simon Urbanek simon.urbanek at r-project.org
Wed Oct 14 15:19:56 CEST 2009

On Oct 13, 2009, at 12:19 , Christoph Hofer wrote:

> Dear list
> I wrote some c-code and would like to link it with the shared  
> library RandomFields.so of the
> RandomFields package.

That's something you cannot do in general, because installed packages  
are just shared objects, not necessarily dynamic libraries (in fact  
some older versions of R used bundles instead). R provides a facility  
for packages to expose their C-level code via R_RegisterCCallable and  
your package can use such entry points using R_GetCCallable. However,  
to my knowledge RandomForests doesn't export its entry point, so you  
cannot them from your C code. That is usually with a good reason,  
because packages are free to change their C-level entry points at any  
point without notice rendering your package useless in the process.

Your options are either to talk to the authors if some general  
abstraction is reasonable or to use the exported entry points from R  
(.C/.Call) or to take and modify their code if the license allows that.


> I tried it in the following way
> gcc -lRandomFields -L/directory of RandomFields.so -o prog my_c_code.c
> and I got the following error
> ld: library not found for -lRandomFields
> collect2: ld returned 1 exit status
> Thus my question: Is it possible to link a shared library (created  
> inside an R-package) with so c-code.
> I am not sure if this is the right list but I am working with Mac OS  
> X 10.6.
> Regards
> Christoph
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac

More information about the R-SIG-Mac mailing list