R-beta: question on dyn.loaded code

Albrecht Gebhardt (agebhard@zidsrv.sci.uni-klu.ac.at)
Thu, 26 Feb 1998 16:35:51 +0100 (CET)


Date: Thu, 26 Feb 1998 16:35:51 +0100 (CET)
From: Albrecht Gebhardt <agebhard@zidsrv.sci.uni-klu.ac.at>
To: r-help@stat.math.ethz.ch
Subject: R-beta: question on dyn.loaded code

Hi,

when designing libraries for R, is it possible to call C/Fortran 
subroutines from other dynamically loaded code?

The following example crashes R:
********* fn1.c *****************
void twice(int *i)
{
  *i =  2 * *i;
}
*********************************
********* fn2.c *****************
extern int twice(int *i);

void negtwice(int *i)
{
  *i = -1 * twice(i);
}
*********************************

$ cc -fpic -c fn1.c
$ ld -shared fn1.o -o fn1.so
$ cc -fpic -c fn2.c
$ ld -shared fn2.o -o fn2.so
$ R

R : Copyright 1997, Robert Gentleman and Ross Ihaka
Version 0.61.1 Alpha (December 21, 1997)

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

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

> dyn.load("fn1.so")
> dyn.load("fn2.so")
> .C("negtwice",as.integer(2))
/usr/local/R/bin/R.binary: can't resolve symbol 'twice'


I guess it will not be possible at all but I'm not sure. Has anyone more 
experience with dynamic loaded code?

Albrecht

------------------------------------------------------------------
Albrecht Gebhardt           email: albrecht.gebhardt@uni-klu.ac.at
Institut fuer Mathematik    Tel. : (++43 463) 2700/837
Universitaet Klagenfurt     Fax  : (++43 463) 2700/834
Villacher Str. 161
A-9020 Klagenfurt, Austria
------------------------------------------------------------------


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._