From owner-freebsd-questions@FreeBSD.ORG Sun Dec 16 17:43:00 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 66416470 for ; Sun, 16 Dec 2012 17:43:00 +0000 (UTC) (envelope-from matthew@FreeBSD.org) Received: from smtp.infracaninophile.co.uk (smtp6.infracaninophile.co.uk [IPv6:2001:8b0:151:1:3cd3:cd67:fafa:3d78]) by mx1.freebsd.org (Postfix) with ESMTP id E1D138FC12 for ; Sun, 16 Dec 2012 17:42:59 +0000 (UTC) Received: from seedling.black-earth.co.uk (seedling.black-earth.co.uk [81.2.117.99]) (authenticated bits=0) by smtp.infracaninophile.co.uk (8.14.5/8.14.5) with ESMTP id qBGHgrBf035684 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sun, 16 Dec 2012 17:42:53 GMT (envelope-from matthew@FreeBSD.org) DKIM-Filter: OpenDKIM Filter v2.7.1 smtp.infracaninophile.co.uk qBGHgrBf035684 Authentication-Results: smtp.infracaninophile.co.uk/qBGHgrBf035684; dkim=none reason="no signature"; dkim-adsp=none (insecure policy) Message-ID: <50CE0816.30509@FreeBSD.org> Date: Sun, 16 Dec 2012 17:42:46 +0000 From: Matthew Seaman User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Manish Jain Subject: Re: Question on how do I tell make to choose between static and shared versions of a library References: In-Reply-To: X-Enigmail-Version: 1.4.6 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig6484B0E92625FDCA2B387E33" X-Virus-Scanned: clamav-milter 0.97.6 at lucid-nonsense.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on lucid-nonsense.infracaninophile.co.uk Cc: freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Dec 2012 17:43:00 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig6484B0E92625FDCA2B387E33 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 16/12/2012 17:22, Manish Jain wrote: > Under /lib I have both versions - shared (libxyz.so.1) as well as stati= c > (libxyz.a) - of a library. How do I tell make to link to the static > version, not the shared one ? The next obvious question is how to do th= e > vice versa - tell make to link to the shared version, not the static on= e. Add -static to the ld command line to produce a staticly linked binary: this forbids ld(1) from doing any dynamic linking. Otherwise ld will default to dynamic linking, but fall back to linking staticly against libraries where there isn't a dynamic shared object available. Actually, there are about 4 different linker flags you could use that mean 'produce a staticly linked binary.' They don't have any different effect; the reason they exist is for historic compatibility with versions of ld(1) from many different sources. It's also an all-or-nothing option. If you wanted to use static linkage for one particular library out of all the libraries used by your program, then you'ld need a very different command line. But that, as they say, is left as an exercise for the student. Cheers, Matthew --=20 Dr Matthew J Seaman MA, D.Phil. PGP: http://www.infracaninophile.co.uk/pgpkey --------------enig6484B0E92625FDCA2B387E33 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.16 (Darwin) Comment: Using GnuPG with undefined - http://www.enigmail.net/ iEYEARECAAYFAlDOCB0ACgkQ8Mjk52CukIyMqQCdHLSTBBgFhj433EJYNT8WkqKO rf4An0sh9J0flcZb2ADAFq0ulCW538Rb =3V17 -----END PGP SIGNATURE----- --------------enig6484B0E92625FDCA2B387E33--