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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8204758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 18:10:26  来源:igfitidea点击:

Boost compiling with MSVC 11 (VS 2012)

c++visual-c++boostvisual-studio-2012boost-build

提问by Loom

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

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

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

EDIT:The Ferruccioanswerworks for VS 2012 Express and Boost 1.51.0 too.

编辑:费鲁乔答案适用于VS 2012 Express和升压1.51.0过。

回答by Contango

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
  • VS2012(Visual Studio 2012 更新 2)
    • VS2015(Visual Studio 2015 更新 2)
  • 视窗 7 x64
    • 或 Windows 10 x64
  • 升压 v1.53
    • 或 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.zipto 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.
  1. 打开 Visual Studio 2012 命令提示符。从开始菜单它:All Programs..Microsoft Visual Studio 2012..Visual Studio Tools..x64 Native Tools Command Prompt
  2. 解压boost_1_53_0.zipC:\boost153.
  3. bootstrap.bat
  4. bjam.exe
  5. 在任何新的 C++ 项目中,包括 Boost 库的路径,如下面的屏幕截图所示。

(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:/boost153to the compiler include pathand C:\boost153\stage\libto 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 foreachloops:

    // 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!
    
  1. 安装 Visual Studio 2012。
  2. 安装更新 2。
  3. 从 SourceForge下载Boost
  4. 解压到“C:\boost153”
  5. 使用管理员权限打开 Visual Studio 命令提示符。从开始菜单,它的All Programs..Microsoft Visual Studio 2012..Visual Studio Tools..x64 Native Tools Command Prompt.
  6. 使用cd c:\boost153.
  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:/boost153compiler include pathC:\boost153\stage\liblinker library path
  14. 右键单击项目,选择Properties,选择Configuration Properties..VC++ Directories。请参阅下面屏幕截图中粗体文本的两个部分): 在此处输入图片说明
  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!
    

More Answers

更多答案

Update 2016-05-05

更新 2016-05-05

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

经过与Win10 x64+ VS2015.2+ Boost v1.6.0

回答by Ferruccio

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
  1. 打开 Visual Studio 命令提示符。从开始菜单它是:所有程序|Microsoft Visual Studio 11|本机 x64 命令提示符。
  2. 解压 boost_1_48_0.zip 并将工作目录设置为 boost_1_48_0
  3. 运行 bootstrap.bat
  4. 运行 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 cclibswhich makes it simpler to build Boost and some other C++ libraries.

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

回答by Gank

bootstrap.bat

引导程序.bat

bjam.exe --toolset=msvc-11

bjam.exe --toolset=msvc-11

回答by GhostlyGhost

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

以下是一些简单的说明,可以在引导时消除警告: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.

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

回答by user610827

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

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

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

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

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

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

回答by Asterisk14

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

除了上述答案之外,我发现BlueGo对使用 MSVC 10/11/12 构建增强版本真的很有帮助。您可以选择不同的配置,只需选择构建,它就可以解决问题。