Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!indri!larry!jwp From: jwp@larry.sal.wisc.edu (Jeffrey W Percival) Newsgroups: comp.unix.questions Subject: help needed in cc library search order Keywords: cc ld library search Message-ID: <176@larry.sal.wisc.edu> Date: 5 May 89 21:23:30 GMT Organization: Space Astronomy Lab, Madison WI Lines: 32 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@larry.sal.wisc.edu)