probe@athena.mit.edu (Richard Basch) (05/27/91)
We are trying to figure out how to build shared libraries and various ways in which they can be used. #1. How does one create shared libraries. For instance, I am trying to build Kerberos on the RS/6000, and from what I can tell you have to be able to resolve all references within the library at the time that you create the shared objects. I wrote a quick script to generate the exported symbols: #!/bin/sh - rm -f $lib shr.o syms.exp lib=$1; shift nm $*|awk 'BEGIN {print "#!"} (NF==3 && $2=="D") {print $3}' > syms.exp ld -r -o shr.o $* -bM:sre -bE:syms.exp -lc ar cru $lib shr.o ranlib -t $lib rm -f shr.o syms.exp (I haven't checked the above for its complete accuracy; I typed it in from memory). Anyway, when I build the DES libraries for Kerberos, there is no problem, as all the symbols will be resolved against libc. When I attempt to build libkrb.a, which depends on libdes.a, I either have to have the libdes.a on the ld line, or specify an import file. I did the latter with the following script (replaces the one above): #!/bin/sh - rm -f $lib shr.o syms.exp syms.imp lib=$1; shift nm $*|awk 'BEGIN {print "#!"} (NF==2 && $1=="U") {print $2}' | sort -u > syms.imp nm $*|awk 'BEGIN {print "#!"} (NF==3 && $2=="D") {print $3}' > syms.exp ld -o shr.o $* -bM:sre -bE:syms.exp -bI:syms.imp -lc ar cru $lib shr.o ranlib -t $lib rm -f shr.o syms.exp syms.imp This seemed to work with libkrb.a (all be it, with a lot of warnings during the execution of the ld command). However, this trick did not seem to work with the next step... I tried the same thing with the libkdb.a library, and found that as soon as a call was made to the kdb portion of the library that the program (kdb_init) died (it core dumped). However, building kdb_init with the static versions of the libraries worked. What am I missing? Is there any documentation on shared libraries that includes examples of how to generate them and what the restrictions are? The only documentation I have seen is under the "ld" command. The description of import/export files leaves a bit to be desired. #2. Lucien (lwvanels@athena.mit.edu) previously asked how to create a statically-resolved binary from one that had previously been resolved with shared libraries. It turns out that this is simple: cc -bnso -bI:/lib/syscalls.exp -o bar foo -L... -L... (The trick was to remember to use -bI:/lib/syscalls.exp). Is there a way to simply statically resolve the contents of one library? I assume that you could extract the shared library and statically link the objects within it and then re-link it against the executable. Does this sound right? Do I need to create import files for the libraries that I build? I assume not, given the contents of /lib/syscalls.exp. I'd prefer if I do not lose the advantage of continuing to use the shared C library. -Richard