[R] error using dyn.load

Tony Long tdlong at uci.edu
Fri Oct 8 03:33:27 CEST 1999

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")
Error in dyn.load(x) : unable to load shared library
  /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];

	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){

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;

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

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

More information about the R-help mailing list