[R] load shared object

Federico Cantini cantini at ifc.cnr.it
Wed Aug 4 12:02:43 CEST 2004


I run R version 1.9.1 and i tried using other name... 


Il mer, 2004-08-04 alle 11:57, Prof Brian Ripley ha scritto:
> Which version of R is this?  (See the posting guide, please.)
> 
> Some versions of R (e.g. 1.8.0) already had "convolve" loaded and you need
> to use another name or use the PACKAGE argument.  It works in the current
> 1.9.1.
> 
> On Wed, 4 Aug 2004, Federico Cantini wrote:
> 
> > Hi all,
> > i have some problem in using shared objects.
> > I tried the example found in "Writing R Extension", pg. 33
> > 
> > I used the .c file prova.c :
> > 
> > -------------------------------------------------------------------
> > #include <R.h>
> > #include <Rinternals.h>
> > 
> > void convolve(double *a, int *na, double *b, int *nb, double *ab)
> > {
> > 	int i, j , nab = *na + *nb - 1;
> > 	
> > 	for (i = 0; i < nab; i++)
> > 		ab[i] = 0.0;
> > 	for (i = 0; i < *na; i++)
> > 		for (j = 0; i < *nb; i++)
> > 			ab[i + j] += a[i] * b [j];
> > }
> > -------------------------------------------------------------------
> > 
> > I generated shared object with 
> > R CMD SHLIB prova.c
> > 
> > i run R and so
> > 
> > > dyn.load("prova.so", local = TRUE, now = TRUE)
> > 
> > >convolve1<-function(a,b).C("convolve",as.double(a),as.integer(length(a)),as.double(b),as.integer(length(b)),ab = double(length(a) + length(b) - 1)$ab)
> > 
> > > a<-1:10
> > > b<-a
> > 
> > typing convolve1(a,b) i get a Segmentation fault.
> > 
> > Can anyone tell me what's the problem
-- 
Federico Cantini <cantini at ifc.cnr.it>




More information about the R-help mailing list