Question on how do I tell make to choose between static and shared versions of a library

Manish Jain bourne.identity at hotmail.com
Sun Dec 16 19:26:16 UTC 2012


On 16-Dec-12 23:12, Matthew Seaman wrote:
> On 16/12/2012 17:22, Manish Jain wrote:
>> Under /lib I have both versions - shared (libxyz.so.1) as well as static
>> (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 the
>> vice versa - tell make to link to the shared version, not the static one.
>
> 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
>
>


Thanks Matthew. That saved me a lot of time, and the man page for ld (as 
suggested by Polytropon) is not as informative on this particular 
subject as your response.


-- 
Regards,

Manish Jain
bourne.identity at hotmail.com



More information about the freebsd-questions mailing list