Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8204033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:45:53+00:00 2026-06-07T07:45:53+00:00

Why are all libraries in Boost not headers-only? Saying it differently, what makes the

  • 0

Why are all libraries in Boost not headers-only?
Saying it differently, what makes the use of .lib/.dll mandatory?

Is it when a class can’t be a template or has static fields?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T07:45:54+00:00Added an answer on June 7, 2026 at 7:45 am

    Different points, I guess.

    • Binary size. Could header-only put a size burden on the client?
    • Compilation times. Could header-only mean a significant decrease in compilation performance?
    • Runtime Performance. Could header-only give superior performance?
    • Restrictions. Does the design require header-only?

    About binary size.

    and a bit of security

    If there’s a lot of reachable code in the boost library, or code about which the compiler can’t argue whether it is reachable by the client, it has to be put into the final binary. (*)

    On operating systems that have package management (e.g. RPM- or .deb-based), shared libraries can mean a big decrease in binary distribution size and have a security advantage: Security fixes are distributed faster and are then automatically used by all .so/.DLL users. So you had one recompile and one redistribution, but N profiteers. With a header-only library, you have N recompiles, N redistributions, always for each fix, and some member of those N are huge in themselves already.

    (*) reachable here means "potentially executed"

    About compilation times.

    Some boost libraries are huge. If you would #include it all, each time you change a bit in your source-file, you have to recompile everything you #included.

    This can be counter-measured with cherry picked headers, e.g.

    #include <boost/huge-boost-library.hpp> // < BAD
    #include <boost/huge-boost-library/just-a-part-of-it.hpp> // < BETTER
    

    but sometimes the stuff you really need to include is already big enough to cripple your recompiles.

    The countermeasure is to make it a static or shared library, in turn meaning "compile completely exactly once (until the next boost update)".

    About runtime performance.

    We are still not in an age were global optimization solves all of our C++ performance problems. To make sure you give the compiler all the information it needs, you can make stuff header-only and let the compiler make inlining decisions.

    In that respect, note that inlining gives not always superior performance because of caching and speculation issues on the CPU.

    Note also that this argument is mostly with regards to boost libraries that might be used frequently enough, e.g. one could expect boost::shared_ptr<> to be used very often, and thus be a relevant performance factor.

    But consider the real and only relevant reason boost::shared_ptr<> is header-only …

    About restrictions.

    Some stuff in C++ can not be put into libraries, namely templates and enumerations.

    But note that this is only halfway true. You can write typesafe, templated interfaces to your real data structures and algorithms, which in turn have their runtime-generic implementation in a library.

    Likewise, some stuff in C++ should be put into source files, and in case of boost, libraries. Basically, this is everything that would give "multiple definition" errors, like static member variables or global variables in general.

    Some examples can also be found in the standard library: std::cout is defined in the standard as extern ostream cout;, and so cout basically requires the distribution of something (library or sourcefile) that defines it once and only once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, first of all I don't want to use Boost, or any external libraries.
We all know about Boost . What other free C++ libraries are worth using?
I must generate a random number using boost libraries, I use this code: boost::mt19937
I'm trying to build only a subset of boost libraries. For example, I have
So I know that the boost libraries are primarily header-only but there are a
Off late I have had too use some template libraries like Boost and Thrust
I'm trying to disable log output from all external libraries in logback-test.xml. Somehow it
is there anyway in QTP to make changes take place on all function libraries
I want to iterate through all loaded shared libraries and get their base addresses
On large-scale Java/.Net Enterprise projects, does every developer need to have all the components/libraries/dependencies

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.