dependencies in .so files
guido@sirio.stat.unipd.it
guido@sirio.stat.unipd.it
Wed, 27 May 1998 19:50:17 +0100 (GMT+0100)
Thomas Lumley writes:
>
>
> I've been trying to get Matt Calder's S compiler to work in R using R
> COMPILE and R SHLIB so it will be fairly platform-independent.
>
> I'm sure someone has claimed in the past that it is possible/easy to
> dyn.load() two dynamic libraries and have one call functions in the other.
> I can't get it to work (Red Hat 5.0/R0.61.1ish). It doesn't seem to matter
> what order I load them in, they can't find each other.
>
> Any ideas?
>From the dlopen man page:
void *dlopen (const char *filename, int flag);
................................................
RTLD_GLOBAL may be or'ed with flag
in which case the external symbols defined in the library will be
made available to subsequently loaded libraries.
So, I try:
1) I modify src/unix/dynload.c changing the flag of dlopen
from RTLD_LAZY to (RTLD_LAZY | RTLD_GLOBAL)
2) build two simple shared libraries the second calling a routine
in the first.
---------------------------a.c-------------------------------
#include <stdio.h>
void a(int *i) {
printf("now in a.so; incrementing i\n");
*i=*i+1;
}
--------------------------b.c--------------------------------
#include <stdio.h>
extern void a(int *i);
void b(int *i) {
printf("in b.so; calling function a in a.so; i=%d\n",*i);
a(i);
printf("in b.so; now i=%d\n",*i);
}
-------------------------Makefile------------------------------
all: a.so b.so
a.o: a.c
gcc -fPIC -c a.c
a.so: a.o
gcc -shared -o a.so a.o
b.o: b.c
gcc -fPIC -c b.c
b.so: b.o
gcc -shared -o b.so b.o
-------------------------------------------------------------------------
Things seems ok.
-------------------------------------------------------------------------
sirio[~/tmp/prova]% R
R : Copyright 1998, Robert Gentleman and Ross Ihaka
Version 0.61.3 (May 3, 1998)
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("a.so")
> dyn.load("b.so")
> y <- .C("b",as.integer(0))
in b.so; calling function a in a.so; i=0
now in a.so; incrementing i
in b.so; now i=1
> y
[[1]]
[1] 1
----------------------------------------------------------------------------
Before introducing the RTLD_GLOBAL flag:
----------------------------------------------------------------------------
sirio[~/tmp/prova]% R
R : Copyright 1998, Robert Gentleman and Ross Ihaka
Version 0.61.3 (May 3, 1998)
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("a.so")
> dyn.load("b.so")
> y <- .C("b",as.integer(0))
in b.so; calling function a in a.so; i=0
/usr/local/src/R-0.61.3/bin/R.binary: can't resolve symbol 'a'
sirio[~/tmp/prova]%
----------------------------------------------------------------------------
I am using R-0.61.3 under Linux 2.30.
guido masarotto
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._