[comp.sys.sgi] Compilation problems with spotlight program

wicks@DCDMJW.FNAL.GOV ("Matthew J. Wicks") (11/22/90)

About 6 weeks ago, I picked up the spotlight program off of this newsgroup.
spotlight is a combination screen locking program and screen-save for
a Personal Iris.

I had no problems using this program until recently. I had recently
installed YP on a group of PI's and now spotlight would no longer work
on the YP client. (It would core dump upon invocation.)

spotlight.c came with the following instructions for compiling:

cc -o spotlight spotlight.c -lgl_s -lc_s -lsun -lm

When I changed it to the following (moving the -lsun)

cc -o spotlight spotlight.c -lsun -lgl_s -lc_s -lm

I got a much larger executable. It appears as if in the original compilation
I did not actually pick up these executables. All is working fine now,
but I am curious on why the order of these libraries made a difference.

Matt Wicks
Fermi National Accelerator Laboratory
708-840-8084
wicks@fnal.fnal.gov

srp@babar.mmwb.ucsf.edu (Scott R. Presnell) (11/22/90)

wicks@DCDMJW.FNAL.GOV ("Matthew J. Wicks") writes:

>I had no problems using this program until recently. I had recently
>installed YP on a group of PI's and now spotlight would no longer work
>on the YP client. (It would core dump upon invocation.)

>spotlight.c came with the following instructions for compiling:
>cc -o spotlight spotlight.c -lgl_s -lc_s -lsun -lm

>When I changed it to the following (moving the -lsun)
>cc -o spotlight spotlight.c -lsun -lgl_s -lc_s -lm

>I got a much larger executable. It appears as if in the original compilation
>I did not actually pick up these executables. All is working fine now,
>but I am curious on why the order of these libraries made a difference.

The order of object files, and therefore libraries (of object files), is
significant in the resolution of function and variable references in that
the first object file to resolve a function or variable "request" is linked
into the executable.

By way of example, I would imagine that spotlight.c has a reference to one
of the getpwent routines (getpwuid() for instance).  In the first "cc" line
above, that function call is resolved first by the -lc_s library - the
normal 'C' library.  The program didn't work because you have now probably
changed your /etc/passwd to have little more than is needed, and the
getpwuid call didn't find what it was looking for, error checking was
minimal, etc.  ---> crash.

But.  When the linker is "presented" the sun library before the C library,
the sun-yp version of the getpwuid routine is linked in and everything is
now fine because the yp version of getpwuid is used with your new yp'ized
/etc/passwd file (the yp versions of the routines are larger because it
takes more code to construct the lowlevel yp calls than it does to read the
/etc/passwd file).  It didn't help to put -lsun *after* -lc_s because
getpwuid had already been resolved by the standard 'C' library by the
time the linker got to the sun library.

The linker considers it an error if functions are multiply defined from
multiple object files.

	- Scott Presnell
--
Scott Presnell				        +1 (415) 476-9890
Pharm. Chem., S-926				Internet: srp@cgl.ucsf.edu
University of California			UUCP: ...ucbvax!ucsfcgl!srp
San Francisco, CA. 94143-0446			Bitnet: srp@ucsfcgl.bitnet