@(#)shared library howto 21 AUG 1997 Rob Thomas robt@cymru.com Howto create a shared library with cc and ld. Having always used ar(1) to create my libraries, I recently switched to cc(1B) and ld(1) to create my shared libs. Here's how: 1. Create as many C source files (.c) as required. I created two: roblib01.c (with four funcs) roblib02.c (with four different funcs) 2. Compile the C source into object code thusly: pudge$ cc -c roblib0?.c You will now have four files, roblib0?.c and roblib0?.o 3. Now create your library with ld(1): pudge$ ld -o libRob.so -G roblib01.o roblib02.o -o is your output file option. -G in dynamic mode, produce a shared object (the goal!). If you get unreferenced symbol errors, use lorder(1) to put your libs in the correct order. For example: ar -cr library `lorder *.o | tsort` That's it! Now link your library in with the -l option to ld. Remember to set your library path with -L, if necessary, to find your library. As always, questions/comments/bugs to: robt@cymru.com Rob Thomas, robt@cymru.com http://www.enteract.com/~robt