C++ - Boost - Setting up on Windows 10

Boost libraries are some of the famous ones in the C++ world.

They contain tons of functionalities but aren't so easy to use or even understand.

First things first, let's try to install it in on our dear Windows 10 operating system.

And test it with Visual Studio 2017.

Ready? Let's do it in this Boost installation tutorial for Windows 10.

First of all

We are going to set up our computer in order to use the following libraries and software:

Setting up Boost libraries

Downloading and installing Boost libraries

The Boost libraries are in general available directly without building anything (only by including headers).

But some libraries have to be built before being able to use them.

That's the case for example for the Boost.Python or Boost.Regex libraries.

It's possible to build these libraries by yourself but to be honest the Boost documentation isn't really crystal clear and some links are even broken.

So to avoid a headache from the sky we are going to use the binaries directly downloaded from SourceForge (link above).

This executable isn't really an installation but more an extraction.
 

Indeed nothing will be changed on your Windows registries, only a new directory will be created with some files within.

So, once the executable donwloaded, Windows will show you a blue window with a message alerting that this is an unrecognized app.

Click on More info at the end of this message to make the Run anyway push button appear

And install it in the following location:

  • C:\soft\boost_1_71_0\

In this directory you can now see another one called lib64-msvc-14.1/ in which there are built libraries, all that in an x64 environment.

Building the Boost.Build (b2) engine

If you want to build libraries from Boost on your own way you'll have to use the Boost.Build tool.

It was in the past called bjam but it's now called b2.

So these 2 tools are exactly the same but the latter is the new version used with Boost.Build.

When you download Boost from the official website, b2 isn't installed.

You have to do it by yourself.

Actually it's quite easy.

Open a console from the Boost directory:

  • C:\soft\boost_1_71_0

Then type the following command:

.\bootstrap.bat

And you'll have on your console after few seconds this message:

PS C:\soft\boost_1_71_0> .\bootstrap.bat

Building Boost.Build engine

Generating Boost.Build configuration in project-config.jam for msvc...

Bootstrapping is done. To build, run:

    .\b2

To adjust configuration, edit 'project-config.jam'.

Further information:

    - Command line help:

    .\b2 --help

    - Getting started guide:

    http://boost.org/more/getting_started/windows.html

    - Boost.Build documentation:

    http://www.boost.org/build/

In the same directory you can now see the b2.exe tool.

We don't need it for now, just let it for the future.

Environment variables for Boost

We have to set our Environment variables.

So add the 2 following paths:

  • C:\soft\boost_1_71_0\
  • C:\soft\boost_1_71_0\lib64-msvc-14.1\

If you are using Windows 10 it's not so unusual to use Visual Studio as well.

So let's set it up to use Boost.

Setting up Visual Studio

Visual Studio platform toolset

We are going to use Visual Studio 2017 so the binaries version are 14.1.

Indeed, each version of Visual Studio has its own platform toolset.

For example:

  • Visual Studio 2017 has a platform toolset 14.1 (often msvc-141)
  • Visual Studio 2019 has a platform toolset 14.2 (often msvc-142)

Yes it's quite vague and not so logical but Miscrosoft is Microsoft.

So download the right one for your Visual Studio version, otherwise it won't work.

Anyway let's set up all that tools.

I'll let you install Visual Studio where you want.

We'll just have to set the include and library directories directly from Visual Studio.

Let's start by creating a Windows Console Application from Visual Studio.

From Visual Studio > File > New Project > Installed > Visual C++ > Windows Desktop > Windows Console Application.

Let's name this project for example like this:

  • Name: BadprogTutorial
  • Location: C:\dev\c++\boost\

Setting the Visual Studio project platform

First thing is now to change the project platform in the Configuration manager:

From Visual Studio > Select the BadprogTutorial.cpp file >  Project > BadprogTutorial Properties... > On upper right click the Configuration Mananger... push button > Change Active solution platform from x86 to x64 > Close.

Then still in the BadprogTutorial Property Pages, at top center, change the platform from Win32 to x64.

Then click OK.

You can stay in Debug mode or change it to Release (it won't change anything for our tutorial).

Setting Visual Studio include paths for Boost

First let's set the includes.

From Visual Studio > Select the BadprogTutorial.cpp file > Project BadprogTutorial Properties... > Configuration Properties > C/C++ > General Additional Include Directories > Edit > Add the following line:

  • C:\soft\boost_1_71_0\
Then OK > Apply > OK.
 

Setting Visual Studio library paths for Boost

We've now to set the libraries.

Same thing but with the linker:

From Visual Studio > Select the BadprogTutorial.cpp file > Project BadprogTutorial Properties... > Configuration Properties > Linker > General Additional Library Directories > Edit > Add the following line:

  • C:\soft\boost_1_71_0\lib64-msvc-14.1\

Then OK > Apply > OK.

Let's code a bit

In our BadprogTutorial.cpp file let's add the following code:

BadprogTutorial.cpp

// badprog.com

#include "pch.h"

#include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>

//
namespace bg = boost::gregorian;

// ----------------------------------------------------------------------------
//
// ----------------------------------------------------------------------------
int main() {
  // date as simple ISO string
  std::string stringDate("20191110");
  bg::date todayDate(bg::from_undelimited_string(stringDate));

  // 
  bg::date::ymd_type ymdDate    = todayDate.year_month_day();
  bg::greg_weekday weekdayDate  = todayDate.day_of_week();

  //
  std::cout 
    << "Tutorial made with love from Badprog.com :D on "
    << weekdayDate.as_long_string() << " "
    << ymdDate.day << " "
    << ymdDate.month.as_long_string() << " "
    << ymdDate.year
    << std::endl;
}

Build and run

Build and run your program, you should see the following appears on your console:

Tutorial made with love from Badprog.com :D on Sunday 10 November 2019

Conclusion

Now that you have installed Boost, plenty of libraries are now available for you.

A lot of fun for the future.

Good job, you did it. cool

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.