Kapil Vyas
Kapil Vyas

Reputation: 667

Which is a better usage variant of linking boost library between single-header, static library and shared library?

Boost provides 3 ways of linking their library: single-header, static library and shared library. Which is the preferred default? What are the pros/cons of using one approach over the other? I seem to prefer the single-header variant since it allows me to avoid the compilation step of a standalone library. And I don't need all the features all at once. I only plan on using Boost's Unit Test framework. Most set-up/getting-started documents always mention the quick and dirty method of using the single-header. This link http://www.boost.org/doc/libs/1_60_0/more/getting_started/windows.html describes "can be used in “header-only” or “separately compiled” mode, although separate compilation is recommended for serious use." - I wonder why serious-use requires compilation - or do we really need to compile?

Upvotes: 0

Views: 221

Answers (1)

Xirema
Xirema

Reputation: 20396

Some Boost Libraries require compilation to be used in your project, and some Boost Libraries require compilation for specific features adjacent to them. So you need to compile Boost if you plan to use any of those libraries/features that require it.

As for choosing between a static and shared library, that's mostly down to personal preference. Generally speaking, when I use Boost, I don't anticipate a scenario where I'm going to pull an ABI-compatible-yet-newer version of Boost, and package that code without changes to my own code. So I pretty much always use Boost (or, more precisely, the portions of boost that require compilation) as static libraries.

Upvotes: 2

Related Questions