*BSD News Article 29957


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!munnari.oz.au!constellation!news.uoknor.edu!ns1.nodak.edu!netnews.nwnet.net!uw-beaver!uhog.mit.edu!europa.eng.gtefsd.com!howland.reston.ans.net!agate!darkstar.UCSC.EDU!news.hal.COM!olivea!grapevine.lcs.mit.edu!ginger.lcs.mit.edu!wollman
From: wollman@ginger.lcs.mit.edu (Garrett Wollman)
Newsgroups: comp.os.386bsd.questions
Subject: Re: How do I create shared libraries for FreeBSD?
Date: 28 Apr 1994 19:20:24 GMT
Organization: MIT Laboratory for Computer Science
Lines: 44
Message-ID: <2pp29o$l74@GRAPEVINE.LCS.MIT.EDU>
References: <179NBN2L@math.fu-berlin.de>
NNTP-Posting-Host: ginger.lcs.mit.edu

In article <179NBN2L@math.fu-berlin.de>,
Gunther Shadow <gusw@zedat.fu-berlin.de> wrote:

>I looked in
>/usr/share/mk/bsd.lib.mk but found only a -Bsharable option.

You were looking in the right place.

SOBJS+= ${OBJS:.o=.so}
lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: ${SOBJS}
        @echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MI
NOR}\)
        @rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
        @$(LD) -Bshareable \
            -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
            ${SOBJS} ${LDDESTDIR} ${LDADD}

If we decode all the variables and make things a bit more readable,
then things get clearer:

	ld -Bshareable -o libfoo.so.13.69 obj1.so obj2.so ... objn.so \
		-L/some/other/dir -lbaz -lblat -lc -lgcc

The notation `objN.so' is used by the standard build environment to
indicate an object file which has been compiled position-indepentent
(i.e., with the `-fpic' or `-fPIC' options to gcc, or the `-k' option
to as), which is mandatory for all input files in a shared library.

If this step suceeds, then you can put the libfoo.so.13.69 somewhere
on the library path set up by ldconfig(8) and then re-run ldconfig to
refresh the cache, and everything will be able to find your new libfoo
library.

(Alternatively, you can just use the Berkeley build environment and
make macros, which will take care of all this automatically; see the
source code to any of the libraries for examples.)

-GAWollman

-- 
Garrett A. Wollman   | Shashish is simple, it's discreet, it's brief. ... 
wollman@lcs.mit.edu  | Shashish is the bonding of hearts in spite of distance.
formerly known as    | It is a bond more powerful than absence.  We like people
wollman@emba.uvm.edu | who like Shashish.  - Claude McKenzie + Florent Vollant