Date: Sun, 16 Dec 2012 17:42:46 +0000 From: Matthew Seaman <matthew@FreeBSD.org> To: Manish Jain <bourne.identity@hotmail.com> Cc: freebsd-questions@freebsd.org Subject: Re: Question on how do I tell make to choose between static and shared versions of a library Message-ID: <50CE0816.30509@FreeBSD.org> In-Reply-To: <BLU0-SMTP1154DEA566E8A9677055BD5F6330@phx.gbl> References: <mailman.67.1355659202.33098.freebsd-questions@freebsd.org> <BLU0-SMTP1154DEA566E8A9677055BD5F6330@phx.gbl>
next in thread | previous in thread | raw e-mail | index | archive | help
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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?50CE0816.30509>