The key is probably to get a newer ld.so ... I believe anything
at 1.7.10 or above will do it; you will want 1.7.11 or better to
fix a bug with dlsym in 1.7.10. Here is a test set; I just checked
it here.
all: mod1.so mod2.so driver
mod1.so: mod1.c
gcc -fPIC -shared mod1.c -o mod1.so
mod2.so: mod2.c
gcc -fPIC -shared mod2.c -o mod2.so
driver: driver.c
gcc driver.c -o driver -ldl
clean:
rm -f mod1.so mod2.so driver
int foo_var = 3;
#include <stdio.h>
extern int foo_var;
int foo_print() {
printf("%d\n", foo_var);
Quote:}
#include <stdio.h>
#include <dlfcn.h>
int main(int argc, char **argv) {
void *handle1, *handle2;
void (*print)();
const char *error;
printf("mod1.so: ");
handle1 = dlopen ("./mod1.so", RTLD_LAZY | RTLD_GLOBAL);
if (!handle1) {
fputs (dlerror(), stderr);
exit(1);
}
printf("loaded.\n");
printf("mod2.so: ");
handle2 = dlopen ("./mod2.so", RTLD_LAZY | RTLD_GLOBAL);
if (!handle2) {
fputs (dlerror(), stderr);
exit(1);
}
printf("loaded.\n");
print = dlsym(handle2, "foo_print");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}
(*print)();
dlclose(handle1);
dlclose(handle2);
Quote:}
enjoy =)
driver.c is prety much from man dlopen, btw...
good luck!
--randy
: hi, I've been puzzled by the mention of an RTLD_GLOBAL flag in the dlopen
: man page; theoretically, you dlopen() a shared object with RTLD_GLOBAL in
: the flags, and the object's symbols are then visible to anything else that
: gets dlopened later. However, when I tried this I discovered that there Is No
: RTLD_GLOBAL defined in the header files!
: I really, really, REALLY need to make loaded modules visible to each other.
: Has anyone done so successfully?
: James