Boost compiling with MSVC 11 (VS 2012)
Asked Answered
P

6

28

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.

Pierrepierrepont answered 20/11, 2011 at 21:12 Comment(1)
d= (◕‿↼ ) unfortunately, not even "Visual Studio 2017" is fully C++11 compliant (I got here while building Boost, which's build section nowadays only mentions their need for C++11 compliant compiler, and NOT with what MSVC version they tested Boost). Microsoft says "Support for C11 and C17 standards is available in Visual Studio 2019 version 16.8 and later", but not tested their claim yet.Sherl
D
32

I managed to get it to build by following these steps:

  1. Open a Visual Studio command prompt. From the start menu it's: All Programs|Microsoft Visual Studio 11|Native x64 Command Prompt.
  2. Unzip boost_1_48_0.zip and set the working directory to boost_1_48_0
  3. run bootstrap.bat
  4. run bjam.exe

It does generate a lot of warnings about not being able to detect the toolkit version, but it proceeds anyway.

Update: I created GitHub repo called cclibs which makes it simpler to build Boost and some other C++ libraries.

Doretha answered 21/11, 2011 at 23:44 Comment(2)
Thanks for this, alot easier than the boost doc's implyKwangju
Beware if you have doskey.exe executing via (HKCU||HKLM)\Software\Microsoft\Command Processor: reg_sz AutoRun. Build caused doskey to crash and build to fail. I have filed a ticket.Disgrace
G
39

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.

Grimes answered 20/11, 2011 at 21:12 Comment(2)
This build not all librariesOlwena
To build other desired libraries, add options to the bjam or b2 command. Some common switches are building libraries for static/shared, x32/x64, etc.Grimes
D
32

I managed to get it to build by following these steps:

  1. Open a Visual Studio command prompt. From the start menu it's: All Programs|Microsoft Visual Studio 11|Native x64 Command Prompt.
  2. Unzip boost_1_48_0.zip and set the working directory to boost_1_48_0
  3. run bootstrap.bat
  4. run bjam.exe

It does generate a lot of warnings about not being able to detect the toolkit version, but it proceeds anyway.

Update: I created GitHub repo called cclibs which makes it simpler to build Boost and some other C++ libraries.

Doretha answered 21/11, 2011 at 23:44 Comment(2)
Thanks for this, alot easier than the boost doc's implyKwangju
Beware if you have doskey.exe executing via (HKCU||HKLM)\Software\Microsoft\Command Processor: reg_sz AutoRun. Build caused doskey to crash and build to fail. I have filed a ticket.Disgrace
Z
8

bootstrap.bat

bjam.exe --toolset=msvc-11

Zeitgeist answered 1/12, 2013 at 3:29 Comment(1)
Or since boost 1.47.0 b2 --toolset=msvc-11. This answer seems far more correct than rerunning bootstrap from the dev shell and ignoring the upcomming warnings.Reactionary
L
5

Check that your installation is correct by confirming the output of the following command:

C:\>echo %VS110COMNTOOLS%
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\

Here's some simple instructions to follow to get rid of warnings when bootstrapping: http://landoftheninja.blogspot.com/2011/11/visual-c-11-and-boost.html

Don't miss his follow-up post that deals with the automatic linking.

Legislator answered 3/3, 2012 at 3:39 Comment(0)
V
0

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

vcvarsall.bat need call a "reg.exe" which in "C:\windows\system32\". if not in search path,will cause this error.

Add C:\windows\system32 to %PATH% will solved the problem.

Violet answered 14/7, 2013 at 11:40 Comment(0)
V
0

In addition to above answers, I find BlueGo really helpful for building boost versions with MSVC 10/11/12. You can select different configurations and just select build, and it does the trick.

Vastah answered 5/8, 2014 at 13:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.