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

Recently, 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.

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 boost_1_53_0.zip. 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: http://www.mingw.org/ and MASM from here: http://www.masm32.com/masmdl.htm. 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

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.

• Scott Cannon

Thanks! This write up was very helpful. I’d been struggling for several hours to get boost compiled for mingw. All the other instructions I found were too out of date to be useful (referred to paths that didn’t exist, etc.).

Your instructions worked on my WinXP system with Mingw & Msys, with one caveat: the bjam binaries were found in a bin.ntx86/ subdirectory. I did take me a minute to realize the command prompt I needed to use/update was the Windows command prompt, not my msys command prompt.

• pkout

I am glad it helped you out! The caveat that you experienced might be related to Windows XP. I was compiling it on Windows 7. Thanks for posting this comment here, though. Someone might find it useful when compiling on Window XP.

• Slava Kroilov

Thank you very much for the guide.
UPD: Since version 1.61 (probably the one even earlier, idk) instead of going to boostboost_1_53_0toolsbuildv2engine dir, it’s just boostboost_1_61_0toolsbuild. Other steps are identical.