Boost compiling with MSVC 11 (VS 2012)

Loom picture Loom · Nov 20, 2011 · Viewed 36.1k times · Source

How to build Boost (I tried version 1.48.0) with Visual Studio C++ 11? bootstrap.bat cannot find toolset vc11. I added toolset vc11 to F:\Programming\boost_1_48_0\tools\build\v2\engine\build.bat but got a message:

ERROR: Cannot determine the location of the VS Common Tools folder.

EDIT: The Ferruccio answer works for VS 2012 Express and Boost 1.51.0 too.

Answer

Contango picture Contango · May 28, 2013

This answer works beautifully for:

  • VS2012 (Visual Studio 2012 Update 2)
    • or VS2015 (Visual Studio 2015 Update 2)
  • Windows 7 x64
    • or Windows 10 x64
  • Boost v1.53
    • or Boost v1.60

In a nutshell

  1. Open a Visual Studio 2012 command prompt. From the start menu its: All Programs..Microsoft Visual Studio 2012..Visual Studio Tools..x64 Native Tools Command Prompt.
  2. Unzip boost_1_53_0.zip to C:\boost153.
  3. run bootstrap.bat
  4. run bjam.exe
  5. In any new C++ project, include the path to the Boost libraries, as per the screenshot below.

(optional) Step-by-Step Instructions

  1. Install Visual Studio 2012.
  2. Install Update 2.
  3. Download Boost from SourceForge.
  4. Unzip into "C:\boost153"
  5. Open a Visual Studio Command prompt with Administrator privileges. From the start menu, its All Programs..Microsoft Visual Studio 2012..Visual Studio Tools..x64 Native Tools Command Prompt.
  6. Change to the boost directory with cd c:\boost153.
  7. Run bootstrap.bat.
  8. Run bjam.exe. This builds all of the libraries.
  9. There may be some warnings, but you can ignore these.
  10. When it has finished compiling after about 5 minutes, it states:

    The Boost C++ Libraries were successfully built!
    The following directory should be added to compiler include paths:
       C:/boost153
    The following directory should be added to linker library paths:
       C:\boost153\stage\lib
    
  11. This is important, we will need to add these two paths to any new C++ project.

  12. Create a new C++ project.
  13. As noted a couple of steps ago, add C:/boost153 to the compiler include path and C:\boost153\stage\lib to the linker library path.
  14. Right click on the project, select Properties, select Configuration Properties..VC++ Directories. See the two portions of bolded text in the screenshot below): enter image description here
  15. Let's run a simple program that shows off the power of boost, by adding support for foreach loops:

    // Source code below copied from:   
    // http://www.boost.org/doc/libs/1_53_0/doc/html/foreach.html
    #include "stdafx.h"
    
    #include <string>
    #include <iostream>
    #include <conio.h> // Supports _getch()
    #include <boost/foreach.hpp>
    
    int main()
    {
        std::string hello( "Hello, world!" );
    
        BOOST_FOREACH( char ch, hello )
        {
            std::cout << ch;
        }
    
        _getch();
        return 0;
    }
    
  16. Result:

    Hello, world!
    

More Answers

Update 2016-05-05

Checked with Win10 x64 + VS2015.2 + Boost v1.6.0.