🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sun
Article #7974

Re: Sun-Spots Digest, v10n86 [Miscellaneous]

#7974
From: Basile STARYNKEVITCH
Date: Tue, 04 Jun 1991 18:40
39 lines
2239 bytes
About dynamic loading, I suggest using the dlopen facilities (describes
in SunOs4.1 man 3 dlopen). I am using them and am very satisfied...
Performances are good (less than 70 microseconds on a Sun 4/60
SparcStation1 to find a newly loaded adress in a 20000 symbols
dynamically loaded library, given its symbol - with the dlsym function)
You should just build a shared library (compiling it with -pic or -PIC option, and ld-ing it with -assert pure-text:
suppose func1 in f1.c, func2 in f2.c
	cc -pic -c f1.c -o f1.o
	cc -pic -c f2.c -o f2.o
	ld -assert pure-text f1.o f2.o -o sharedlib.so)

Then in your program - ommitting test stuff:
	#include <dlfcn.h>

	void *libhandle;
	void (*myloadedfunc1) ();
	void (*myloadedfunc2) ();
	libhandle = dlopen("sharedlib.so", 1);
	/* if (!libhandle) error... */
	myloadedfunc1 = dlsym(libhandle, "_func1");
	/* if (!myloadedfunc1) error... */
	myloadedfunc2 = dlsym(libhandle, "_func2");
	/* if (!myloadedfunc2) error... */
	/* call to func1(1):: */
	(*myloadedfunc1) (1);

Caveat:: the dynamically loaded functions - here func1 and func2 should call external functions or variables already in your program: either in  an initially used shared library such as libc.*.so, or in your *.o, or already referenced in a statically linked library. For instance, if func1 calls pprintf in static lib: libcps.a, you should reference pprintf in you bare program - for instance in a static routine or array). Of course, two different dynamically loaded libraries cannot reference to each other wi




thout using global functions pointers such as myloadedfunc1...

Basile STARYNKEVITCH
Commissariat a l'Energie Atomique
DMT/SERMA
CE. Saclay bat470
91191 GIF/YVETTE CEDEX
France
Technical Details
Message-ID: <3083@brchh104.bnr.ca>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!cunews!bnrgate!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-request

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!cunews!bnrgate!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-request
From: basile@soleil.cea.fr (Basile STARYNKEVITCH)
Newsgroups: comp.sys.sun
Subject: Re: Sun-Spots Digest, v10n86 [Miscellaneous]
Keywords: No Digest Subjects in Unmoderated Mode
Message-ID: <3083@brchh104.bnr.ca>
Date: 4 Jun 91 18:40:00 GMT
Sender: news@brchh104.bnr.ca
Organization: Sunspots, Psuedo-Unmoderated
Lines: 37
Approved: sun-spots@rice.edu
X-Original-Date:    10 May 91 10:27:03+0200