[R] error using dyn.load

Thomas Lumley thomas at biostat.washington.edu
Fri Oct 8 03:11:39 CEST 1999


On Thu, 7 Oct 1999, Tony Long wrote:

> I am trying to use dynamic loading of an outside C routine.  I am
> attempting 6.12.1 of Phil Spector's book.  When I try to load the object
> file I get an error I don't understand:
> 
> > dyn.load("runa.o")


You need to make a shared library (.so) not an object file. The easy way
to do this is

R SHLIB runa.c

which is set up by the R configure process to use the right compile and
link flags.

You also should change the type of integers passed to C from "long" to
"int" for R.  For gcc under x86 Linux it doesn't matter, though.

See the help for SHLIB, COMPILE, and .C for more information.


Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle	




> Error in dyn.load(x) : unable to load shared library
> "/usr/home/tdlong/run_avg/runa.o":
>   /usr/home/tdlong/run_avg/runa.o: ELF file's phentsize not the expected size
> 
> 
> I am running version 0.64.2 or R under Linux Red Hat 5.2
> 
> here is the C code I made an object for, I compiled with
> 
> gcc -m486 -c runa.c
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <time.h>
> 
> void runavg(double *x, long n, long k, double *r);
> void runa(double *x, long *n, long *k, double *r);
> 
> void runavg(double *x, long n, long k, double *r){
> 
> /*
> x is the input vector
> n is the length of the vector
> k is the size of the running average window, the window includes the data point
> 		at that position plus k points on either side.  For example
> k = 3 would be
> 		a sliding window of size {3+1+3}= 7 centered on each point
> r is the output vector
> */
> 
> 	long i,j,l,u;
> 	double t;
> 
> 	t = 0;
> 
> 	for(j=0; j<=k; j++) t += x[j];
> 
> 	l=0;
> 	u=k;
> 	for(i=0; i < n; i++){
> 	/* the use of u-l-1 instead of k handles end effects */
> 		r[i] = t / (double)(u-l+1);
> 	/* update the current running total for the next position */
> 		if(i > k -1) t -= x[l++];
> 		if(u < n -1) t += x[++u];
> 		}
> 
> }
> 
> void runa(double *x, long *n, long *k, double *r){
> 	runavg(x,*n,*k,r);
> }
> 
> /*
> void main(void)
> {
> 
> double x[20]={2,5,3,6,2,2,1,6,8,9,10,2,4,6,7,4,3,1,8,10}, r[20];
> long n,k,i;
> 
> runavg(x,20,3,r);
> for(i=0; i<20; i++) printf("%g\t%g\n",x[i],r[i]);
> }
> */
> 
> 
> Tony Long
> Ecology and Evolutionary Biology
> Steinhaus Hall
> University of California at Irvine
> Irvine, CA
> 92697-2525
> 
> Tel:  (949) 824-2562   (office)          ****NOTE NEW AREA CODE****
> Tel:  (949) 824-5994   (lab)              ****NOTE NEW AREA CODE****
> Fax: (949) 824-2181                        ****NOTE NEW AREA CODE****
> 
> email:  tdlong at uci.edu 
> 
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 

Thomas Lumley
------------------------------------------------------+------
Biostatistics		: "Never attribute to malice what  :
Uni of Washington	:  can be adequately explained by  :
Box 357232		:  incompetence" - Hanlon's Razor  :
Seattle WA 98195-7232	:				   :
------------------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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