Compile C++ Boost Libraries in Windows 7 Using MinGW and MASM

By Petr Kout, March 21, 2013

Compile C++ Boost Libraries in Windows 7 Using MinGW and MASMRecently, I needed the C++ Boost library to perform some object serialization. Installing and compiling Boost on my Windows 7 machine using MinGW was a task I spent quite a few hours on before I succeeded to follow the right steps. So I decided to share the process with others who might have similar difficulties.

First, we need to download Boost. Get it from here:

In this example, we will install Boost in C:\Program Files (x86)\boost directory. If that directory doesn’t exist, create it on your PC or use your own desired location. So once you downloaded the Boost zip file, put it in the C:\Program Files (x86)\boost directory.

Next, unzip the file. In my case, I downloaded the version So after unzipping it, it created the directory boost_1_53_0.

Now, before we start compiling Boost, let’s make sure MinGW32 is installed and also MASM32. You can get MinGW from here: and MASM from here: Make sure you get the 32 bit versions as those are the ones this tutorial is about.

Once you download MinGW and MASM, install them and make sure that you add paths to their bin directories to your system wide environmental variable Path.

Okay, after adding the paths to the Path variable, close the command prompt and open it again to reflect the changes in the Path in it. Now, in your command prompt, go to the directory C:\Program Files (x86)\boost\boost_1_53_0\tools\build\v2\engine. Of course, if you downloaded a different version, the boost directory will have a different number as a part of its name. Once you are there, run:

build.bat mingw

This will compile bjam and create two new files in the subdirectory bin.ntx86: b2.exe and bjam.exe. Copy these two files to your C:\Program Files (x86)\boost\boost_1_53_0\ directory.

Change your command prompt directory to the C:\Program Files (x86)\boost\boost_1_53_0\ directory and run this command to compile Boost:

bjam --toolset=gcc

(As a side note: If you have 64 bit MinGW on your PC and you want to compile boost in 64 bit mode, make sure your system PATH variable contains only the path to the 64 bit version MinGW and then run the above command with an extra argument like this: bjam –toolset=gcc address-model=64.)

This will start the compilation process. It will take time, so be patient.

I use Eclipse IDE to program in C/C++. So in order to compile a project that uses Boost libraries, you will need to add this directory to your project library includes under C/C++ Build -> Settings section of your project properties window:

C:\Program Files (x86)\boost\boost_1_53_0

and this one to your MinGW linker libraries search paths:

C:\Program Files (x86)\boost\boost_1_53_0\stage\lib

You will also need to add the individual libraries to the list of used library files. Those libraries are the names of the files in the C:\Program Files (x86)\boost\boost_1_53_0\stage\lib directory, without the lib prefix and the .a postfix in the file name. So for an example, if you want to use the libboost_atomic-mgw46-mt-1_53.a library, you will need to add boost_atomic-mgw46-mt-1_53 to your linker libraries list. Once you add all the needed libraries, you will be able to compile a project using Boost.

I hope this helps someone.