使用MSVC 11进行编译(VS 2012)

时间:2011-11-20 21:12:17

标签: c++ visual-c++ boost visual-studio-2012 boost-build

如何使用1.48.0构建 Boost (我尝试使用版本Visual Studio C++ 11)? bootstrap.bat无法找到工具集vc11。我将工具集vc11添加到F:\Programming\boost_1_48_0\tools\build\v2\engine\build.bat,但收到了一条消息:

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

编辑: Ferruccio answer适用于VS 2012 Express和Boost 1.51.0。

6 个答案:

答案 0 :(得分:39)

这个答案非常有效:

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

简而言之

  1. 打开Visual Studio 2012命令提示符。从开始菜单开始:All Programs..Microsoft Visual Studio 2012..Visual Studio Tools..x64 Native Tools Command Prompt
  2. boost_1_53_0.zip解压缩为C:\boost153
  3. 运行bootstrap.bat
  4. 运行bjam.exe
  5. 在任何新的C ++项目中,包括Boost库的路径,如下面的屏幕截图所示。
  6. (可选)分步说明

    1. 安装Visual Studio 2012。
    2. 安装更新2.
    3. 下载Boost from SourceForge
    4. 解压缩为“C:\ boost153”
    5. 使用管理员权限打开Visual Studio命令提示符。从开始菜单中All Programs..Microsoft Visual Studio 2012..Visual Studio Tools..x64 Native Tools Command Prompt
    6. 使用cd c:\boost153更改为boost目录。
    7. 运行bootstrap.bat
    8. 运行bjam.exe。这构建了所有库。
    9. 可能会有一些警告,但您可以忽略这些警告。
    10. 大约5分钟后完成编译后,它会说:

      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. 这很重要,我们需要将这两个路径添加到任何新的C ++项目中。

    12. 创建一个新的C ++项目。
    13. 如前几步所述,将C:/boost153添加到compiler include path,将C:\boost153\stage\lib添加到linker library path
    14. 右键单击项目,选择Properties,然后选择Configuration Properties..VC++ Directories。请参阅下面屏幕截图中的粗体文本的两部分): enter image description here
    15. 让我们运行一个简单的程序,通过添加对foreach循环的支持来展示boost的强大功能:

      // 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. 结果:

      Hello, world!
      
    17. 更多答案

      更新2016-05-05

      选中Win10 x64 + VS2015.2 + Boost v1.6.0

答案 1 :(得分:32)

我设法按照以下步骤进行构建:

  1. 打开Visual Studio命令提示符。从开始菜单开始:所有程序| Microsoft Visual Studio 11 | Native x64命令提示符。
  2. 解压缩boost_1_48_0.zip并将工作目录设置为boost_1_48_0
  3. 运行bootstrap.bat
  4. 运行bjam.exe
  5. 它确实会产生很多关于无法检测工具包版本的警告,但无论如何都会继续。

    更新:我创建了名为cclibs的GitHub仓库,这使得构建Boost和其他一些C ++库变得更加简单。

答案 2 :(得分:8)

bootstrap.bat

bjam.exe --toolset = msvc-11

答案 3 :(得分:5)

通过确认以下命令的输出来检查您的安装是否正确:

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

以下是一些简单的说明,可以在引导时删除警告:http://landoftheninja.blogspot.com/2011/11/visual-c-11-and-boost.html

不要错过他关于自动链接的后续帖子。

答案 4 :(得分:0)

vs2012 ERROR:无法确定VS Common Tools文件夹的位置。

vcvarsall.bat需要在“C:\ windows \ system32 \”中调用“reg.exe”。 如果不在搜索路径中,将导致此错误。

将C:\ windows \ system32添加到%PATH%将解决问题。

答案 5 :(得分:0)

除了上述答案,我发现BlueGo对于使用MSVC 10/11/12构建boost版本非常有帮助。您可以选择不同的配置,只需选择构建,它就可以实现。

相关问题