Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.rmit.EDU.AU!news.unimelb.EDU.AU!munnari.OZ.AU!news.Hawaii.Edu!news.uoregon.edu!hunter.premier.net!www.nntp.primenet.com!nntp.primenet.com!howland.erols.net!feed1.news.erols.com!uunet!in1.uu.net!fu-berlin.de!irz401!orion.sax.de!uriah.heep!news From: j@uriah.heep.sax.de (J Wunsch) Newsgroups: comp.unix.bsd.freebsd.misc Subject: Re: [Help] Dynamic Link libraries Date: 25 Oct 1996 22:49:12 GMT Organization: Private BSD site, Dresden Lines: 72 Message-ID: <54rg58$9ta@uriah.heep.sax.de> References: <Dzo4KJ.A96.B.ss1@bath.ac.uk> Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) NNTP-Posting-Host: localhost.heep.sax.de Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: knews 0.9.6 X-Phone: +49-351-2012 669 X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F 93 21 E0 7D F9 12 D6 4E ccsmh@bath.ac.uk (Mark Harding) wrote: > The problem is this: I have a small program that uses the dlopen(), > dlsym() etc functions to access functions in a Dynamic Library. I can > get this test program to run under SunOs and Linux but not under FreeBSD. This is my first attempt to play with this either, but just for fun, here's what works for me: j@uriah 809% cat dlib.c #include <stdio.h> int sayhello(void) { printf("I'm saying hello only.\n"); return 0; } j@uriah 810% cat test.c #include <dlfcn.h> int main(void) { void *cookie; typedef int ext_t (void); ext_t *sayhello; if ((cookie = dlopen("shlib.so", 1)) == 0) return 1; if ((sayhello = (ext_t *)dlsym(cookie, "_sayhello")) == 0) return 2; return sayhello(); } j@uriah 811% cat Makefile all: test shlib.so test: test.o cc -o test test.o shlib.so: dlib.o ld -o shlib.so -Bshareable dlib.o dlib.o: dlib.c cc -c dlib.c -fPIC clean: rm -f *.o *.so test j@uriah 812% make cc -O -c test.c cc -o test test.o cc -c dlib.c -fPIC ld -o shlib.so -Bshareable dlib.o j@uriah 813% ./test I'm saying hello only. j@uriah 814% echo '/saying/s/say/not say/\ ? w\ ? q' | ed dlib.c 91 95 j@uriah 815% make cc -c dlib.c -fPIC ld -o shlib.so -Bshareable dlib.o j@uriah 816% ./test I'm not saying hello only. -- cheers, J"org joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-)