Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Mar 1996 10:41:40 -0700 (MST)
From:      Terry Lambert <terry@lambert.org>
To:        humprey@linux1.dlsu.edu.ph (Humprey C. Sy)
Cc:        msmith@atrad.adelaide.edu.au, questions@freebsd.org
Subject:   Re: Compiling with shared libraries
Message-ID:  <199603011741.KAA14436@phaeton.artisoft.com>
In-Reply-To: <Pine.LNX.3.91.960301143546.1369B-100000@ccslinux.dlsu.edu.ph> from "Humprey C. Sy" at Mar 1, 96 03:03:24 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> > > 	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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199603011741.KAA14436>