Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!think.com!mintaka!bloom-beacon!sunbim.be!db From: db@sunbim.be (Danny Backx) Newsgroups: comp.windows.x Subject: Re: SUMMARY ld.so __XtInherit not found Message-ID: <9011150830.AA07172@sunbim.be> Date: 15 Nov 90 08:59:58 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 62 > So, can someone that really understands the shared vs. static libraries > explain what is happening here. Sure. I'll start at the beginning. Sun's shared libraries have 2 parts. One is called the SO part, and is truly shared, the other is the SA part, and is not shared. You can find these things as e.g. -rw-r--r-- 1 root 7996 Feb 8 1990 /usr/lib/libc.sa.1.5 -rwxr-xr-x 1 root 516096 Feb 8 1990 /usr/lib/libc.so.1.5 The shared part contains everything you don't write to. The unshared part contains the rest. This rest is essentially [read this thoroughly] : initialized global variables, except if they are read-only. There are several gothas here. 1. You need to compile the library with option -pic (or -PIC), because the SO part gets linked into the program on addresses unknown in advance. 2. If your program somewhere contains a comparison to a routine name, the routine being in the shared library, then you better be real careful about this. (This is less valid if you as a user link with a shared library, but certainly true if you write a shared library. I.e. if, in the library code, you do this type of comparison, then the routine must be put in the SA part.) 3. This one is the one that is bugging you. I think it is a /bin/ld bug, Sun probably thinks differently. You need to have an unresolved reference to one of the symbols in the SA part in your program. In practice, this means that YOUR PROGRAM must have a reference to _XtInherit in it. If you don't have this, then ld will forget to link in the SA part. Now if you write a decent program (i.e. one that initializes the toolkit), then you will automatically have this. If, however, your program is weird in the sense that it uses certain Xt routines, without ever calling XtInitialize or something similar, then you have a problem. A nice example of this is OSF's uil compiler. It uses XtMalloc and related stuff all the time, but it doesn't open any connection to an X server. So what you need to do in order to compile this successfully with shared library is put in a reference to _XtInherit. You can do this by putting a call to XtInitialize() in the main program, for instance after the exit() statement. (Right, you don't even need to call it. Just make sure it's in there.) Two more notes : 1. Don't ask me how Sun makes sure that /lib/libc.sa.* always gets linked into your program. Maybe they hacked up ld ? 2. The people who bought our Motif 1.1 package know how I resolve these problems for them. Danny Backx BIM Networks System Engineer E-Mail: db@sunbim.be (or uunet!mcsun!ub4b!sunbim!db) Telephone: +32(2)759.59.25 Fax : +32(2)759.47.95 Postal Mail : Danny Backx BIM Kwikstraat 4 3078 Everberg Belgium