Date: Tue, 29 Jun 1999 17:36:38 +0700 (NSS) From: Max Khon <fjoe@iclub.nsu.ru> To: hackers@freebsd.org Subject: dlopen returns non NULL Message-ID: <Pine.BSF.4.05.9906291726460.1300-100000@iclub.nsu.ru>
next in thread | raw e-mail | index | archive | help
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 majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9906291726460.1300-100000>