Boost logo

Boost Users :

Subject: Re: [Boost-users] msvc linker wants to prepend "lib" to library names
From: Lars Viklund (zao_at_[hidden])
Date: 2012-02-03 10:44:48


On Fri, Feb 03, 2012 at 03:24:00PM +0000, Andy Falanga (afalanga) wrote:
> Thank you for clarifying this one. The first response didn't fit what
> I'd found on-line from many sources (to include boost.org).
>
> > What you describe is what the -s- tag indicates, namely whether the C++
> > runtime library is statically or dynamically linked. The presence of -
> > s-
> > means that the static runtime is used. The lack of it means that the
> > dynamic runtime is used.
>
> I finally found the auto_link.hpp file but I admit that I don't fully
> understand it. How does the system know to arrange for static over
> dynamic linking? This was quite confusing to me. For the moment, the
> problem is fixed with the inclusion of the macro BOOST_DYN_LINK in the
> additions I've made to the solution.

For reference, the set of user-configurable defines are listed at:
http://www.boost.org/doc/libs/1_48_0/libs/config/doc/html/index.html#boost_config.configuring_boost_for_your_platform.user_settable_options

It also mentions that some libraries must be statically linked on some
platforms, while some must be dynamically linked.

> For my own understanding, although we're making a DLL in this solution,
> would we want to use static linking or dynamic? I think I realize that
> the answer to this may possibly be, "It depends on your needs and that
> of your customer." However, this discussion has come up on the team
> since I've inadvertently "discovered" this issue. If you're making
> a DLL, what would be the "preferred" or "best practice" approach for
> linking with the Boost libraries?

I've only been able to come up with two reasons why you would prefer to
link Boost dynamically over linking it statically:

1. If you pass Boost types across a DLL interface boundary, you probably
want to use a dynamic Boost library such that the same code runs in each
module in your program that uses the types. If the Boost code is
entirely contained inside of a module, this should not be necessary.
For some libraries (I'm guessing Serialization), this could be very
beneficial and would probably get rid of some of the more common
multi-module issues people tend to encounter.

2. If you have multiple modules using the same Boost library, you might
be able to reduce the code duplication between the modules by using
dynamic Boost libraries, as the code then resides mostly in the shared
library.

The downsides of dynamic linking is that there's some state shared
betwen the modules that use Boost in your project, and that no
dead-code-elimination linker optimizations take place when dynamically
linked, so your total deployment size may be larger.

There is also the problem of having to deploy the DLLs separately in
your installer, and if your program ends up in the %PATH%, the DLLs may
interfere with other programs in the system by being accidentally
loaded.

Personally, I do not use the dynamic Boost libraries unless I have a
concrete known benefit from using them. Static is always my default, and
is the Boost auto-link default on Windows as far as I know.

As for why your system might be preferring the dynamic libraries, there
might be some environment variable or personal user setting in your
project. Try looking for whether you have some personal customizations
to your build settings or environment on your workstation.

-- 
Lars Viklund | zao_at_[hidden]

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net