On 3/15/2021 7:48 AM, Damian Vicino via Boost wrote:
Hi, I was reading the development section of the docs: https://www.boost.org/development/index.html And, I noticed there was nothing in the development guidelines about when to implement as headers-only vs built library. I got my own ideas of why most libraries are headers-only. But, I was wondering if someone with the historical context (someone who was here when those first libraries were developed) can share how boost got into the current shape and what new library developers should look into when deciding to go headers-only or not. I appreciate any anecdotes, guidelines, tradeoffs, thumb rules, comments on the topic. I would love to collect as much as possible here in this thread and write something to post in the development doc section in the website for future reference.
I think this is a great topic, even if it is not directly related to Boost but more related to C++ and use of class and function templates, inline code versus out-of-line code, declarations versus definitions. In the past, when working as a consultant for various companies, I created numerous libraries for code reuse, mostly DLLs under Windows. I recall that these libraries were essentially divided by .h/.hpp header files with their declarations and .cpp source files with their definitions. It seemed natural then that the .cpp files would be compiled into object files and those object files would become a DLL with its own API documentation based on header file declarations/constructs. With templates, of course, the line between declarations and definitions is blurred since template declarations/definitions are rarely divided between source and header files. Of course any library can be a mixture of templates, plain classes, functions and whatever. But in Boost entire libraries are just templates, especially class templates, and this very often leads to header-only libraries. But I admit I would love to hear from others about this issue of when to create purely header-only libraries versus shared ( or static ) libraries, or of shared ( or static libraries ) with a mixture of header-only code. So hopefully others can offer their wisdom and experience in this area.
Best, Damian