Boost - Installation

Instal Boost libraries under Windows

This tutorial explains how to obtain and instal Boost libraries under Windows, DevC++ IDE and MinGW compiler. For more detailed install guide, read official Getting started guide. Installation is pretty easy, and using Boost libraries is even easier.

Author tested solution presented here on Boost 1.33, Dev-C++ 4.9.9.2 and MinGW 3.4.2. The tutorial is provided "as is" without expressed or implied warranty.

Goal

This guide will try to explain how to obtain, install and use Boost libraries. This is focused on:

If you want to install Boost under Linux or under MSVC, I suggest you look into official Getting started guide, which explains a lot more that this simple tutorial.

Prerequisites

You should know how to use Windows, Internet and you should be a C++ programmer. Besides these obvious requirements, you should have:

Although Boost installation file is about 20MB, you really need more than 3GB of free space.

If you are not familiar with Dev-C++ or MinGW, I'm working on some tutorials, so check wagjo.com later.

1. Download

You will need to download latest Boost from here. I recommend taking .exe version of Boost, but you can also grab a zip version.

Secondly, you will need Boost Jam. You must download ntx86 version, because we are using Windows.

Unpack Boost and bjam.exe (Boost Jam) into same directory. I have everything in C:\Boost\. Unpacking Boost and Boost Jam will create some directory structure other from the one we want so do some dir moving. At the end, your Boost should look like this:Boost directory structure

Important !

I do not recommend having spaces in Boost path, some problems may arise. So don't unpack boost in "C:\Program Files\" directory

Do not run bjam.exe yet! You need to specify some command line parameters and if you don't, bjam will try to install Boost with settings we don't like.

2. Installation

Run bjam with these parameters:

bjam.exe "-sMINGW_ROOT_DIRECTORY=C:\Dev-Cpp" "-sTOOLS=mingw" install

where C:\Dev-Cpp is path of your Dev-Cpp and MinGW. Again Dev-C++ should be installed in path containing no spaces.

If you use STLport with mingw, installation is different. Consult official guide.

If you don't know how to run bjam with some parameters, learn how to use Windows and then come back!

After executing bjam, installation will begin and warning will tell us that Python library is skipped. It's OK, because we don't have python installed :).

(Oh well, boost installation finished with errors on my PC. I had several internal compiler errors: Segmentation fault, At least boost::wave had problems compiling)

Installation is very long, about 15 minutes or more, so be prepared.

After Installation, your Boost should look like this:Boost directory structure after installation

Among others, 2 very important directories have been created in your Boost directory:

First directory (x_xx will be replaced with current version of Boost) is where all header files are stored. We will have to point Dev-D++ to that directory so it can find boost header files. To do that, add that directory as C++ Include directory in Tools-Compiler Options-Directories-C++ includes. You can see it in following picture (replace x_xx with your Boost version):Dev C++ options 1

Second directory is where static and dynamic libraries are stored. As before, we must point Dev-C++ there. Again we can do it in compiler option, this time in Libraries section:Dev C++ options 2

After that you can start using boost in your programs!

3. Usage

We will create simple program to test if Boost is working.

You don't have to include additional libraries into your program most of time, because Boost libraries are often very small and consist only from header files.

However some bigger libraries do have .lib files you must include in your project.

We will use boost::date_time library which has one additional library we must include. To do that, go to Project-Project Options-Parameters, click on Add library or Object, find libboost_date_time-mgw.lib in your boost\lib directory and add it. Result should look like this:Dev C++ options 3

Note: there are several types of libraries in your boost\lib directory. Some of them are used if you want to use dynamic boost libraries, some of them if you want to statically link boost libraries in you program. Some of libraries have debug information and some work in multi-threading environment. To learn about which library is which, read Getting started guide

Simple program to test Boost:

// modified example from
// http://boost.org/doc/html/date_time/examples.html

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

int main()
{
	using namespace boost::gregorian;
	using namespace std; // OK for simple program like this

	// The following date is in ISO 8601 extended format
	string s("2001-10-9");
	date d(from_simple_string (s));
	cout << to_simple_string(d) << endl;

	// Read ISO Standard (CCYYMMDD) and output ISO Extended
	string ud("20011009");
	date d1(from_undelimited_string (ud));
	cout << to_iso_extended_string (d1) << endl;

	// Output the parts of the date - Tuesday October 9, 2001
	date::ymd_type ymd = d1.year_month_day();
	greg_weekday wd = d1.day_of_week();
	cout << wd.as_long_string() << " "
	     << ymd.month.as_long_string() << " "
	     << ymd.day << ", " << ymd.year << endl;

	cin.ignore (numeric_limits<int>::max(), '\n');
}

Notice how boost header files are included. Every boost header is in /boost directory and boost header files end with .hpp

Note: If you get linker errors, undefined references, you haven't included correct library in project options.

Note: I assume you know how to use Dev-C++, if not, go and learn it. I'm also preparing some Dev-C++ tutorials, so check wagjo.com later

See also

Boost: Introduction

External Links

Boost

Getting started guide

This page has been accessed 64524 times