Edan Maor
Edan Maor

Reputation: 10052

Using Boost on Windows (Visual Studio)

I want to get started using Boost. I'm programming a C++ program in Visual Studio (obviously on a Windows machine).

Boost's Getting Started Guide says:

The easiest way to get a copy of Boost is to use an installer. The Boost website version of this Getting Started guide will have undated information on installers as they become available, or see Boost downloads or the installer provided by BoostPro Computing. We especially recommend using an installer if you use Microsoft Visual Studio, because the installer can download and install precompiled library binaries, saving you the trouble of building them yourself.

I'm a little unsure if I want to follow this advice, or just download and build everything myself. Potential problems that I see with an installer are:

  1. Things are no longer self-contained (i.e. every team member has to install Boost, then configure Visual Studio to recognize it).
  2. I can't keep Boost under source control (I would ideally like it to be soure files in my source control like everything else). (Edit: Judging by the comments, it looks like boost is kinda large (as in 5 GB!), so obviously I'd need to keep only parts of it under source control).

So my question is, am I just being paranoid and should go the installer route, or am I correct and should build it myself? If anyone has any experience working with Boost and Visual Studio, I'd appreciate if they could share their views on this (and if it should be to build it myself, any tips would also be appreciated, for example should I only copy every file that I actually use? etc.).

Note:

A few similar questions on StackOverflow, but which didn't ask this explicitly, make me think that I shouldn't use the installer, which is why I'm asking it explicitly here. For reference, these are the questions:

  1. Boost linking, Visual Studio & version control
  2. Including Relevant Boost Libraries with C++ Source (Using Visual Studio)

Upvotes: 5

Views: 5720

Answers (10)

Shital Shah
Shital Shah

Reputation: 68728

I'd say, just make Boost installation as prerequisite for your project. The manual installation takes just few minutes with one-time small number of steps. Most large size complex project, eventually end up taking up dependency on Boost so its not unusual to make it prerequisite. Of course, it's trivial to automate it. The advantages are:

  1. You don't add giant Boost distribution in your repo
  2. You don't have to cherry-pick what you use
  3. Other projects can share the installation
  4. One-time setup also takes care of building header+cpp libraries

For Visual Studio 2015 and latest Boost version, here are the step-by-step instructions we follow for our team:

https://stackoverflow.com/a/39628306/207661

Upvotes: 0

T.E.D.
T.E.D.

Reputation: 44804

We actually create our own installer, with just the parts of Boost that we use in our jobs, and give that out to the IT folks to install on developer machines. We also keep that copy of boost in revision control, so we can track dependencies between it and the rest of our system properly, and build it ourselves.

I suppose work-wise this is the worst of both worlds. But it does give us the maximum control.

Upvotes: 1

Sergei
Sergei

Reputation: 71

I would recommend to run bootstrap.bat first - it will build bjam.exe and then

bjam --stagedir="c:\Program Files\Boost" --build-type=complete --toolset=msvc-9.0 --with-regex --with-date_time --with-thread --with-signals --with-system --with-filesystem --with-program_options stage

bjam --stagedir="c:\Program Files\Boost" --build-type=complete --toolset=msvc-10.0 --with-regex --with-date_time --with-thread --with-signals --with-system --with-filesystem --with-program_options stage

..

You just need to specify the correct toolset. It will put all binaries to the ..\lib folder.

Upvotes: 0

the_mandrill
the_mandrill

Reputation: 30842

One other thing to consider is whether you need all or part of boost. What we do here is put the source in version control and create a single wrapper project for the libraries that we actually want to use. The individual libraries are written cleanly enough to make it a matter of just dropping all the cpp files into a new visual studio project. You might need to set up the top level configuration header (I think I set this as a forced include) and the whole thing built very easily. Add this project as a dependency in your solution and it means you can keep all the binaries out of the SCM and also ensure that everyone is always up-to-date.

Much of boost is headers-only anyway so you may find that there's only a handful of libraries that you'd want to build. This approach makes it easier for you to match your VS project settings too.

Upvotes: 1

ravenspoint
ravenspoint

Reputation: 20462

I recommend using the installer.

Building it yourself is not hard. Here is the procedure:

    Download boost into C:\Program Files\boost\boost_1_40_0

Open the command prompt and change your current directory to the Boost root directory

bootstrap

.\bjam

The library binaries are now sprinkled through the folders under 
C:\Program Files\boost\boost_1_40_0\bin.v2 
Find the required libraries and copy them to 
C:\Program Files\boost\boost_1_40_0\lib

( Do not confuse folders called lib and libs! )

However, this is slow enough and just complicated enough, especially the last step, that you and everyone else will probably screw something up once in a while, resulting in a waste of many hours sorting out mysterious build errors - this is my experience anyway.

Upvotes: 3

Brian R. Bondy
Brian R. Bondy

Reputation: 347216

A good way to make sure everyone has everything configured properly is to use svn externals. You can create something like /trunk/boost1.35 and then you can point to that with an svn external.

That way as new versions of boost come out, you can just repoint your svn external to /trunk/boost1.40

In your repository, your svn external points to that svn folder within your repository. Example /depends/boost

We personally keep the boost header files under source control as described but keep the libs as a zip that we require everyone to download. We have an environment variable something like the following BOOST_LIB and we point that to the current boost library directory.

Upvotes: 8

Stack Overflow is garbage
Stack Overflow is garbage

Reputation: 247969

  1. Things are no longer self-contained (i.e. every team member has to install Boost, then configure Visual Studio to recognize it).
  2. I can't keep Boost under source control (I would ideally like it to be soure files in my source control like everything else).

Before you put Boost under source control, keep in mind that the compiled libraries take up several gigabytes. (my Boost folder is around 5GB) It might be worth just letting everyone install Boost for themselves.

Apart from this, the installer should work fine, but compiling it yourself is really trivial as well.

Boost installs into version-specific folders by default (both if you compile it yourself and if you use the installer), so it's easy enough to have multiple versions installed side by side. So if your team upgrades Boost to a new version, you could simply change the include path in the .sln or .vsprops files to make the compiler search for the new version -- if a coworker hasn't installed the right version, he just won't be able to build (which might be preferable to silently building with an old version)

Upvotes: 1

DevSolar
DevSolar

Reputation: 70263

I have built Boost under Windows. Its "bjam" installation tool auto-detects MSVC and uses it for compiling; I wouldn't have any reservations against building yourself. It's only marginally more difficult than "./configure && make && make install", really.

Building yourself could even be necessary, because the Boost libs available online do not include ICU (Unicode) support, e.g. for the boost_regex lib.

Upvotes: 2

Jeff Paquette
Jeff Paquette

Reputation: 7127

I'd use the installer, unless you need to customize the build flags. It's much easier, and building boost (at least the last time I did it) wasn't the clearest process. There's nothing stopping you from downloading the source that matches the version of boost that the installer gives you, and putting that in version control. This is the approach I've used in the past for other libraries (nss, iplanet sdk) and it's worked well.

Upvotes: 0

EFraim
EFraim

Reputation: 13028

Several points NOT to keep it under source control:

  1. Boost is huge.
  2. Compilation is non-trivial (esp. for several configurations)
  3. Compilation is long (you don't want every developer to do it)

I personally would not bother building it myself - on Linux, for instance I always use the distribution provided package.

Upvotes: 0

Related Questions