30

Boost is meant to be the standard non-standard C++ library that every C++ user can use. Is it reasonable to assume it's available for an open source C++ project, or is it a large dependency too far?

Coding Mash
  • 3,338
  • 5
  • 24
  • 45
dajobe
  • 4,938
  • 35
  • 41

10 Answers10

45

Basically your question boils down to “is it reasonable to have [free library xyz] as a dependency for a C++ open source project.”

Now consider the following quote from Stroustrup and the answer is really a no-brainer:

Without a good library, most interesting tasks are hard to do in C++; but given a good library, almost any task can be made easy

Assuming that this is correct (and in my experience, it is) then writing a reasonably-sized C++ project without dependencies is downright unreasonable.

Developing this argument further, the one C++ dependency (apart from system libraries) that can reasonably be expected on a (developer's) client system is the Boost libraries. I know that they aren't but it's not an unreasonable presumption for a software to make.

If a software can't even rely on Boost, it can't rely on any library.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • See Anders answer about the bcp utility. That will allow us to use boost in our project where we've avoided it in the past due to size. – Mark Borgerding Mar 15 '12 at 20:42
  • @Mark I don’t understand the “due to size” answer. Boost is a *collection of libraries*. Most of those libraries are tiny in size. No separate tool is needed for that. – Konrad Rudolph Mar 15 '12 at 22:05
  • 2
    If most of them are tiny in size, I guess I've not wanted to use those. The ones I've seen are so interconnected that they end up bloating our code tarball by tens of megabytes. We ship code to customers that they expect to be able to compile on multiple linux distros. There are too many changes between versions to simply tell our customers that boost is a pre-req. The huge size of boost prevents us from bundling it with our code. The boost library developers seem to never think about limiting code size. e.g. boost_1_49_0/boost/typeof/vector200.hpp is over 2MB in one source file – Mark Borgerding Mar 16 '12 at 02:24
  • "If a software can't even rely on Boost, it can't rely on any library." I just checked and the standard boost distribution contains about 40,000 source files... that's a heck of a dependency! – Tom Swirly Apr 22 '12 at 23:45
  • @TomSwirly Have you counted the size of other frameworks? Furthermore, Boost is highly *modular*. Apart from the fact that many of its libraries are header only – meaning you can just drop in the necessary headers in your project – all can be installed separately. Admitted, Boost *could* make this easier but installing all of Boost is absolutely straightforward, and *distributing* its binaries also is. – Konrad Rudolph Apr 23 '12 at 07:00
  • As a concrete example, I was wanting to use "bind" only. I have my own hand-rolled one which takes half a dozen include files... but bcp tells me that in order to include bind, I'd need to bring in 447 include files from boost... – Tom Swirly Apr 24 '12 at 15:42
  • @Tom Yes. I concede that the module dependency structure in Boost is far from ideal. On the other hand, this makes it vastly easier for Boost contributors to write compiler-independent code that even works on older, defective compilers. Without these dependencies this would be completely impossible. Standing on the shoulders of giants and all that. The solution is not ideal but IMHO the lesser of all evils. – Konrad Rudolph Apr 24 '12 at 15:48
  • 1
    I'm not coming out for or against using Boost! I'm merely saying that it's a heavy dependency, compared to most libraries. In my current project I have several other dependencies - their size, put together, is a small fraction of Boost's size. But if you need it for your core functionality, you really need it! So the answer isn't "If a software can't even rely on Boost, it can't rely on any library." but "It depends." – Tom Swirly Apr 24 '12 at 18:46
  • "If a software can't even rely on Boost, it can't rely on any library." disagree. A software can rely on system libraries as well as the standard c++ library. The more dependencies you add to a project, the more things outside of your control can break. Just because library A works well on project B, doesn't mean an update won't break it on project C. – rxantos Mar 03 '22 at 18:17
28

Take a look at http://www.boost.org/doc/tools.html. Specifically the bcp utility would come in handy if you would like to embed your boost-dependencies into your project. An excerpt from the web site:

"The bcp utility is a tool for extracting subsets of Boost, it's useful for Boost authors who want to distribute their library separately from Boost, and for Boost users who want to distribute a subset of Boost with their application.

bcp can also report on which parts of Boost your code is dependent on, and what licences are used by those dependencies."

Of course this could have some drawbacks - but at least you should be aware of the possibility to do so.

Anders Hansson
  • 3,746
  • 3
  • 28
  • 27
13

I used to be extremely wary of introducing dependencies to systems, but now I find that dependencies are not a big deal. Modern operating systems come with package managers that can often automatically resolve dependencies or, at least,make it very easy for administrators to install what is needed. For instance, Boost is available under Gentoo-Postage as dev-libs/boost and under FreeBSD ports as devel/boost.

Modern open source software builds a lot on other systems. In a recent study, by tracking the dependencies of the FreeBSD packages, we established that the 12,357 ports packages in our FreeBSD 4.11 system, had in total 21,135 library dependencies; i.e., they required a library, other than the 52 libraries that are part of the base system, in order to compile. The library dependencies comprised 688 different libraries, while the number of different external libraries used by a single project varied between 1 and 38, with a mode value of 2. Furthermore, 5,117 projects used at least one external library and 405 projects used 10 or more.

In the end the answer to your question will come from a cost versus benefit analysis. Is the benefit of re-using a mature, widely used, reviewed, and tested library like Boost and larger than the low and falling cost of a dependency? For any non-trivial use of Boost's facilities the answer is that you should go ahead and use Boost.

Community
  • 1
  • 1
Diomidis Spinellis
  • 18,734
  • 5
  • 61
  • 83
4

KDE also depends on Boost.

However it mostly depends on your goals, and even more so on your target audience, rather than the scope of your project. for example TinyJSON (very small project), is almost 100% Boost, but thats fine because the API it provides is Boost-like and targeted at Boost programmers that need JSON bindings. However many other JSON libraries don't use Boost because they target other audiences.

On the other hand I can't use Boost at work, and I know lots of other developers (in their day jobs) are in the same boat. So I guess you could say if your Target is OpenSource, and a group that uses Boost, go ahead. If you target enterprise you might want to think it over and copy-paste just the necessary parts from Boost(and commit to their support) for your project to work.

  • Edit: The reason we can't use it at work is because our software has to be portable to about 7 different platforms and across 4 compilers. So we can't use boost because it hasn't been proven to be compatible with all our targets, so the reason is a technical one. (We're fine with the OpenSource and Boost License part, as we use Boost for other things at times)
Robert Gould
  • 68,773
  • 61
  • 187
  • 272
  • 1
    I'm curious why you couldn't use it at work, fear of open source risks? Or some more technical reason? – dajobe Sep 24 '08 at 14:41
  • 2
    I thought that boost was regularly tested on like 12 systems and 10212 compilers?(Exaggeration of course). But I know they do a lot of testing on a lot of systems. – Raindog Oct 23 '08 at 06:48
  • Yes Boost works great on most platforms, but for critical embedded devices (such as military and medical), and many games machines(my case) there is no assurance that it will work correctly (and there are cases that its broken on some platforms). – Robert Gould Oct 25 '08 at 12:51
4

It depends. If you're using a header file only defined class template in Boost - then yes go ahead and use it because it doesn't suck in any Boost shared library, as all the code is generated at compile time with no external dependencies. Versioning problems are a pain for any shared c++ library, and Boost is not immune from this, so if you can avoid the problem altogether it's a good thing.

4

The benefits of using boost when writing C++ code that they significantly outweigh the extra complexity of distributing the open source code.

I work on Programmer's Notepad and the code takes a dependency on boost for test, smart pointers, and python integration. There have been a couple of complaints due to the requirement, but most will just get on with it if they want to work on the code. Taking the boost dependency was a decision I have never regretted.

To make the complexity slightly less for others, I include versioned pre-built libraries for boost python so that all they need to do is provide boost in their include directories.

Simon Steele
  • 11,558
  • 4
  • 45
  • 67
3

I would say yes. Both Mandriva (Red Hat based) and Ubuntu (Debian based) have packages for the Boost libriaries.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
J.J.
  • 4,856
  • 1
  • 24
  • 29
  • yes I noticed it was packaged (and on for example MacPorts) but it's rather large. some other people have answered that that it's had complaints – dajobe Sep 24 '08 at 14:43
2

I think the extensive functionality that Boost provides and, as you say, it is the standard non-standard C++ library justifies it as a dependency.

Drew Stephens
  • 17,207
  • 15
  • 66
  • 82
1

Unfortunately yes, for ubuntu they're readily available but for RHEL 4&5 I've almost always ended up making them from tarballs. They're great libraries, just really big... like using a rail spike when sometimes all you really need is a thumbtack.

David
  • 17,673
  • 10
  • 68
  • 97
1

It all depends on the way you're going to use Boost. As Diomidis said, if you're going to use some non-trivial facilities from Boost, just go ahead. Using libraries is not a crime.

Of course, there are many people who prefer not to use Boost, because introducing new dependencies has always some cons and extra worries, but in an open source project... in my opinion it's even alright to use them if you just want to learn them or improve your skills on them.

David
  • 2,663
  • 3
  • 24
  • 41