shared libraries, when to use them

der Mouse mouse at thunder.mcrcim.mcgill.edu
Tue Jun 18 15:01:50 AEST 1991


In article <1991Jun11.163544.20234 at aio.jsc.nasa.gov>, shirley at 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 at larry.mcrcim.mcgill.edu



More information about the Comp.unix.programmer mailing list