Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!mouse From: mouse@thunder.mcrcim.mcgill.edu (der Mouse) Newsgroups: comp.unix.programmer Subject: Re: shared libraries, when to use them Keywords: shared libraries .so Message-ID: <1991Jun18.050150.17149@thunder.mcrcim.mcgill.edu> Date: 18 Jun 91 05:01:50 GMT References: <1991Jun11.163544.20234@aio.jsc.nasa.gov> Organization: McGill Research Centre for Intelligent Machines Lines: 69 In article <1991Jun11.163544.20234@aio.jsc.nasa.gov>, shirley@washington.jsc.nasa.gov (Bill Shirley) writes: > I was wondering when it's appropriate to use shared libraries? > (specifically in SunOS) You can't, because SunOS doesn't have shared libraries. (What it does have is shared object files. What's the difference? You can link in part of a library without linking in the rest, among other things.) This confusion is understandable, since Sun documentation says "shared libraries" where they mean shared object files. Assuming you really meant shared objects.... > Is it ever appropriate for non OS work? I'm not sure what you mean by "OS work", so it's hard to say. > How exactly do you build it? (in SunOS) What *I* do is to type "make"; the Makefile worries about the rest. Presumably you would like to know what's in the Makefile, then :-) Here, for example, is the Makefile from one directory in which I have source that gets compiled and put into a shared "library": .c.o: $(CC) $(CFLAGS) -pic -c $< mv $*.o $*.so $(CC) $(CFLAGS) -c $< install: cp *.o o-files/unshared cp *.so o-files/shared ( cd o-files ; make $(MFLAGS) install ) And then o-files/Makefile: install: ( cd unshared ; make $(MFLAGS) install ) ( cd shared ; make $(MFLAGS) install ) and o-files/shared/Makefile (o-files/unshared/Makefile is an uninteresting exercise in the user of ar): install: -@ rm -f lib.so -@ ( ls -1 *.so | sed -e 's/\(.*\).so$$/mv \1.so \1.o/' ) 2> /dev/null | sh -v ld -assert pure-text -o lib.so *.o cp lib.so /the/installed/version/of/lib.so.1.5 > When you compile something with a -Bstatic flag, where does it get > its code from? Does it extract the object part needed from the > shared library (lib*.so.#[.#])? No. A shared "library" cannot be broken up. When you use -Bstatic, ld doesn't look for .so files; it pays attention to .a files only, just the way it used to before .so files came along. Yes, this can lead to version skew if the .a and .so files were built from incompatible versions of the .o files. That's the library maintainer's lookout. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu