From owner-freebsd-hackers Tue Jun 29 3:39:28 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from iclub.nsu.ru (iclub.nsu.ru [193.124.222.66]) by hub.freebsd.org (Postfix) with ESMTP id B86CF14C39 for ; Tue, 29 Jun 1999 03:37:07 -0700 (PDT) (envelope-from fjoe@iclub.nsu.ru) Received: from localhost (fjoe@localhost) by iclub.nsu.ru (8.9.3/8.9.3) with ESMTP id RAA01519 for ; Tue, 29 Jun 1999 17:36:38 +0700 (NSS) (envelope-from fjoe@iclub.nsu.ru) Date: Tue, 29 Jun 1999 17:36:38 +0700 (NSS) From: Max Khon To: hackers@freebsd.org Subject: dlopen returns non NULL Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 void f() { printf("Hello, world!\n"); g(); } --- cut here --- --- cut here (main4.c) --- #include #include #include 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