Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Mar 1996 17:47:39 +1030 (CST)
From:      Michael Smith <msmith@atrad.adelaide.edu.au>
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:  <199603010717.RAA00513@genesis.atrad.adelaide.edu.au>
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
Humprey C. Sy stands accused of saying:
> > 
> > If that's really a shared library, it should be libmac.so.1.0.  How
> > are you building it?  If you were using the standard /usr/share/mk 
> > templates it'd be named correctly.
> 
> I used the bsd.lib.mk template.  It produced libmac.a, that's all.  
> What's the difference between <lib>.a and <lib>.so.X.X files anyway?  I 
> thought they're both the same, save for compatibility reasons only.

No.  libname.a is a normal 'ar' format library.  You need to define
SHLIB_MAJOR and SHLIB_MINOR to get the standard template to produce
a shared library.  An example :

#
# Makefile for the vhf70 interface library
#

LIB=    vhf70_if
SRCS=   if_misc.c if_rtc.c if_rm.c if_sc.c if_dc.c if_ac.c if_id.c if_ds.c if_gc
.c if_tx.c if_md.c
NOPROFILE=      yes

DEBUG_FLAGS=    -g
CFLAGS=         -Wall

SHLIB_MAJOR=    1
SHLIB_MINOR=    1

.include <bsd.lib.mk>


> > > about is how come if I have to compile it together with my c program, I 
> > > have to place the option "-lmac" at the end of the command. i.e.
> > > 
> > > 	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?

Because it reads the commandline left to right.  It picks up dependencies
and resolves them as it goes.  In the normal case, it finds the
dependencies in 'zo.c', and resolves them when it's reading the library.
In your reversed case, there's nothing for it to search through afterwards.

> - Humprey -

-- 
]] Mike Smith, Software Engineer        msmith@atrad.adelaide.edu.au    [[
]] Genesis Software                     genesis@atrad.adelaide.edu.au   [[
]] High-speed data acquisition and      (GSM mobile) 0411-222-496       [[
]] realtime instrument control          (ph/fax)  +61-8-267-3039        [[
]] Collector of old Unix hardware.      "Where are your PEZ?" The Tick  [[



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