[R] question about dyn.load()

About this list Date view Thread view Subject view Author view Attachment view

From: xt_wang@cs.concordia.ca
Date: Thu 13 May 2004 - 10:48:26 EST


Message-id: <1084409306.40a2c5da38db9@mailhost.cs.concordia.ca>

Hello, everybody,

I met a big problem. What I want is to use c code in R. I have load a test
code “conv.c” in R and run it successfully. However, in my real code, I use
matlab c library (Matrix Inverse function). After I use command “ R CMD SHLIB”
to share library, I can not use “dyn.load” to load the object in
R. “undefined symbol: mclCleanupProtectedItems” always be mentioned.

My question is that whether I can compile, load and use a c code in R which
includes other library. If I can, How can I do? Could you help me find out
where is the error during the whole operation? If I can not load a c code with
other library in R, can I load a c code with R library in R ( which include
matrix inverse function)? If so, where can I find the R library with matrix
inverse function that has a c interface?

I will appreciate very much if somebody can help me resolve this problem.

Thanks in advance!

Yours,

Maggie

The whole successful and failed process are as follows:

[credsim@confsys ~/src]$ R CMD SHLIB ~/src/conv.c
make: `/home/credsim/src/conv.so' is up to date.
[credsim@confsys ~/src]$ R

R : Copyright 2003, The R Foundation for Statistical Computing
Version 1.8.1 (2003-11-21), ISBN 3-900051-00-3

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for a HTML browser interface to help.
Type 'q()' to quit R.

> dyn.load("./conv.so")
> "%+%" <- function(a,b)
+ .C("conv", as.double(a), as.integer(length(a)),
+ as.double(b), as.integer(length(b)),
+ ab=double(length(a)+length(b)-1))$ab
> u <-rep(1,5)
> u %+% u
[1] 1 2 3 4 5 4 3 2 1

“conv.c”
void conv (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;j<*nb;j++)
     ab[i+j]+=a[i]*b[j];
}

The new operation process with matlab c library :

[credsim@confsys ~/src]$ R CMD SHLIB ~/src/conv.c
gcc -I/usr/local/lib/R/include -I/usr/local/include -D__NO_MATH_INLINES -
mieee-fp -fPIC -g -O2 -c /home/credsim/src/conv.c -o /home/credsim/src/conv.o
gcc -shared -L/usr/local/lib -
o /home/credsim/src/conv.so /home/credsim/src/conv.o
[credsim@confsys ~/src]$ R

R : Copyright 2003, The R Foundation for Statistical Computing
Version 1.8.1 (2003-11-21), ISBN 3-900051-00-3

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for a HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> dyn.load("./conv.so")
Error in dyn.load(x, as.logical(local), as.logical(now)) :
        unable to load shared library "/b2/home/credsim/src/./conv.so":
  /b2/home/credsim/src/./conv.so: undefined symbol: mclCleanupProtectedItems
>

new code “ conv.c”

#include "/a3/matlab/extern/include/matlab.h"
#include <math.h>

void conv (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;j<*nb;j++)
     ab[i+j]+=a[i]*b[j];
}

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:09 EST