Subject: Re: [Boost-build] Linker library ordering
From: Vladimir Prus (vladimir.prus_at_[hidden])
Date: 2016-07-12 14:07:46
On 09-Jul-16 12:41 AM, Nogradi, Chris wrote:
> The following line in unix.jams generated-targets() rule (line 64 in
> sources = $(sources2) [ unix.order-libraries $(libraries) ] ;
> causes the link order to change when building with the gcc toolset.
> However when building with msvc, the link order is maintained based on
> the order of the sources as they are declared in the targets used.
> Before I provide a working example of this showing the disparity between
> the two toolsets, I wanted to first understand the reason this is done.
> Especially seeing that different toolsets could potentially produce
> different results.
the reason we're doing this is that Unix linker is sensitive to the
order of static libraries. If you have
g++ -o binary main.o -la -lb
then only symbols in a that are known to be needed are included. So, if
library b depends on a, those symbols won't be resolved, because at the
time the linker processes -la, it haven't yet processed -lb and
therefore does not know about any needed symbols.
it seems that this is now the case for shared libraries as well.
Now, there's an option to GNU linker that say "please do for static
libraries what MSVC does" - which is to iterate symbol resolution
process until it stabilizes. However, it does not appear to work
for shared libraries.
Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk