[R] Problem with dyn.load()

Prof Brian D Ripley ripley at stats.ox.ac.uk
Tue Apr 16 09:08:11 CEST 2002


On Mon, 15 Apr 2002, Francisco J Molina wrote:

> I tried to dynamically load a c++ function. Everything seems to be OK
> when dyn.load() is  executed but then I get this error
>
>
> Error in .C("integral", sumInMean, sumInVar, boundError,
> numberSampleClasses,  :
>         C/Fortran function name not in load table
>
>
> The code of the function is something like this:
>
> #include <cmath>
>
> extern "C" {
> #include "/usr/local/include/gsl/gsl_statistics_double.h"
> #include "/usr/local/include/gsl/gsl_randist.h"
> #include "/usr/local/include/gsl/gsl_roots.h"
> #include "/usr/local/include/gsl/gsl_sf_erf.h"
> #include "/usr/local/include/gsl/gsl_math.h"
> #include "/usr/local/include/gsl/gsl_integration.h"
>
> void integral( arguments ){
> ...
> return;
> }
> }
>
> I compile with:
>
> g++ -c integral.C -fPIC -I/usr/local/include/gsl -o integral.o; R CMD
> SHLIB integral.o
>
> What could go wrong? The function modify its arguments ( the arguments
> are  pointers )
>
> I put my function with the C header directives in extern{}.
>
> gsl is a library written in C, so I put the gsl's header directives also
> inside extern{}.
>
> I placed in my compiling directory a Makevars file with this content:
>
> PKG_LIBS = -lm -lgsl -lgslcblas
>
> and my R code looks like:
>
> dyn.load('/usr/local/lib/libgslcblas.so',F,)
> dyn.load('/usr/local/lib/libgsl.so',F,)
> dyn.load('/home/f/p/integral.so')

Why are you doing this?  Only the last should be necessary. The
dynamic module integral.so will be linked against any dynamic libraries
on which it depends by the dlopen call underlying dyn.load (at least
on common implementations of dlopen).

The first thing to do is to check what symbols integral.so exports (with nm
-g) and what it depends on (with R CMD ldd integral.so since the R script
sets LD_LIBRARY_PATH).

You haven't told us your OS or compiler.  An experiment with what you gave
(and no content to the integral function) worked for me on Solaris 2.7 and
gcc 3.0.4 with just the final dyn.load.  (Not a complete test, of course,
since gsl was not really being used.)

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

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list