help needed in cc library search order

Jeffrey W Percival jwp at larry.sal.wisc.edu
Sat May 6 07:23:30 AEST 1989


I am working with Ultrix 2.2 and the C compiler, and I just got real
confused about linking a main program with several subroutine libraries
that contain identically named routines.  Here's the big picture:
suppose I have a main program that calls a "mid-level" routine mid(),
which in turn calls a "low-level" routine low().  I want to link to
different versions of low(), depending on which version of main() I
am building.

Here's the calling tree:

	main()
	    mid()
		low()

I have 2 libraries: lib1 has mid() and low() in it,
lib2 has a different low() (same name, different code).
Let's call the first version of low "low1()" and the other "low2()",
even though their real names are identical.

Case 1:	cc main.o lib1.a
does just as I'd suspect.  I get main, mid, and low1().

Case 2: cc main.o lib2.a lib1.a

The mystery:  I would have thought that I would get low2() always,
because lib2 preceeds lib1.  HOWEVER,  I get low1() unless I
make a call to low2() in main().  In other words, the linker
chooses differently depending on whether main() makes a call to low().

Can someone help me understand this?
-- 
Jeff Percival (jwp at larry.sal.wisc.edu)



More information about the Comp.unix.questions mailing list