From owner-freebsd-questions Fri Mar 1 09:50:45 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id JAA27377 for questions-outgoing; Fri, 1 Mar 1996 09:50:45 -0800 (PST) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id JAA27372 for ; Fri, 1 Mar 1996 09:50:44 -0800 (PST) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id KAA14436; Fri, 1 Mar 1996 10:41:40 -0700 From: Terry Lambert Message-Id: <199603011741.KAA14436@phaeton.artisoft.com> Subject: Re: Compiling with shared libraries To: humprey@linux1.dlsu.edu.ph (Humprey C. Sy) Date: Fri, 1 Mar 1996 10:41:40 -0700 (MST) Cc: msmith@atrad.adelaide.edu.au, questions@freebsd.org In-Reply-To: from "Humprey C. Sy" at Mar 1, 96 03:03:24 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-questions@freebsd.org Precedence: bulk > > > cc -O2 zo.c -lmac > > > > > > If I try to include "-lmac" before zo.c, the procedures compiled in > > > libmac.a won't be seen at all, and the compiler returns errors saying > > > these procedures are unreferenced from text segment. Why is this so? > > > > The linker commandline is read left to right > > I still don't get the difference. Either way both files will be linked > together, so why can't the linker find those procedures in libmac.a if I > typed -lmac before zo.c? A library is a set of optional objects. The objects are pulled in if there exists references to the symbols they export at the time the link occurs. If you link the library first, no symbol references exist in the linker, and nothing is pulled in. This is why you have to link X programs -lXt -lXext -lX11. Since the objects in the library are examined in order, in turn, this is why you have to run "ranlib" on libraries to generate crossreferences to cause the objects to be pulled in (even if they are interdependent). You probably don't care about all this, since you didn't want a non-shared library (like you have) anyway. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.