Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!spool.mu.edu!think.com!linus!philabs!ttidca!alter From: alter@ttidca.TTI.COM (Steve Alter) Newsgroups: comp.unix.wizards Subject: Re: dynamic linking C code with ld link editor Message-ID: <23325@ttidca.TTI.COM> Date: 13 Feb 91 03:09:27 GMT References: <23713@netcom.COM> Organization: Citicorp/TTI, Santa Monica Lines: 47 In article <23713@netcom.COM> aed@netcom.COM (Andrew Davidson) writes: } I am trying to fiqure out how to use the ld link editor to dynamicly link } some C code. Are there any refference? All I have are the man pages } which are less than usefull for the beginer } } I am working on a sun workstation, but must also get this to run on a } sys V unix(SCO ODT UNIX sysV 3.2.0). This info is for SunOS (4.1, but I believe also applies to 4.0.) Load the "shlib.etc" package from your distrubution media (under 4.1 the command to do this is "/usr/etc/install/add_services") and then look in directory /usr/lib/shlib.etc at the README and Makefile files. That stuff only describes how to build a new version of the shared libc library, but it shows some of the basics that might be useful/needed in building your own library. Highlights: -- You have to build all of your object modules (for this library) with the "-pic" option to generate position-independent (a.k.a. relocatable) code. -- The Makefile uses the "-assert pure-text" option on the "ld" command to ensure (I believe) that everything in the library is read-only, i.e. no writable global data areas because read-only is a must for anything that is shared between anonymous users. If you want a global writable buffer then you've got to create a shared-memory segment. -- The Makefile also plays some games to ensure that the object modules go into the library in the correct order. The concepts of ranlib and the __.SYMDEF module don't apply to shared libraries because they're mapped directly into the address space of the process, whereas a normal library is just a collection of .o files with a symbol table up front and .o files still have to be linked with ld. Read the "ld" manual-page very carefully as it explains a lot of how the ld and ld.so programs, the LD_LIBRARY_PATH, and the version numbers on the /usr/lib/lib*.s[ao].* files work together. My ultimate suggestion: buy a set of the manuals; there's a whole chapter on shared libraries in there. -- Steve Alter {philabs,psivax,pyramid,quad1,rdlvax,retix,rutgers}!ttidca!alter Transaction Technology Inc. a subsidiary of Citicorp (213) 450-9111 x2541