hi, there!
in the following code `dlopen' returns NULL
on the first iteration (because g() is not defined) -- it's ok
but on the second iteration `dlopen' returns "valid" dlh
I need the code like this to load some functions dynamically.
The code below shows that it's unable to ensure that all the symbols
in .so to be loaded can be properly resolved AND try again (with
recompiled module) if dlopen fails first time. Any suggestions?
--- cut here (Makefile) ---
CFLAGS = -g
all: dl.so main4
dl.so: dl.c
gcc -o dl.so $(CFLAGS) -shared -fpic -fPIC dl.c
main4: main4.o
gcc -o main4 -export-dynamic main4.o
clean:
rm -f dl.so main4.o
--- cut here ---
--- cut here (dl.c) ---
#include <stdio.h>
void f()
{
printf("Hello, world!\n");
g();
}
--- cut here ---
--- cut here (main4.c) ---
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
main()
{
void *dlh = NULL;
void (*f)(void);
for (;;) {
getchar();
if (dlh != NULL) {
dlclose(dlh);
dlh = NULL;
}
dlh = dlopen("./dl.so", RTLD_NOW);
if (dlh == NULL) {
fprintf(stderr, "dlopen: %s\n", dlerror());
continue;
}
f = dlsym(dlh, "f");
if (f == NULL) {
fprintf(stderr, "dlsym: %s\n", dlerror());
dlh = NULL;
continue;
}
f();
}
dlclose(dlh);
return 0;
}
--- cut here ---
/fjoe
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message