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
Boost compiling with MSVC 11 (VS 2012)
提问by Loom
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:
如何使用Visual Studio C++ 11构建Boost(我尝试了1.48.0版)?找不到工具集。我添加了工具集 vc11但收到一条消息:bootstrap.bat
vc11
F:\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)
- or
- 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
简而言之
- 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
. - Unzip
boost_1_53_0.zip
toC:\boost153
. - run
bootstrap.bat
- run
bjam.exe
- In any new C++ project, include the path to the Boost libraries, as per the screenshot below.
- 打开 Visual Studio 2012 命令提示符。从开始菜单它:
All Programs..Microsoft Visual Studio 2012..Visual Studio Tools..x64 Native Tools Command Prompt
。 - 解压
boost_1_53_0.zip
到C:\boost153
. - 跑
bootstrap.bat
- 跑
bjam.exe
- 在任何新的 C++ 项目中,包括 Boost 库的路径,如下面的屏幕截图所示。
(optional) Step-by-Step Instructions
(可选)分步说明
- Install Visual Studio 2012.
- Install Update 2.
- Download Boost from SourceForge.
- Unzip into "C:\boost153"
- 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
. - Change to the boost directory with
cd c:\boost153
. - Run
bootstrap.bat
. - Run
bjam.exe
. This builds all of the libraries. - There may be some warnings, but you can ignore these.
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
This is important, we will need to add these two paths to any new C++ project.
- Create a new C++ project.
- As noted a couple of steps ago, add
C:/boost153
to thecompiler include path
andC:\boost153\stage\lib
to thelinker library path
. - Right click on the project, select
Properties
, selectConfiguration Properties..VC++ Directories
. See the two portions of bolded text in the screenshot below): 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; }
Result:
Hello, world!
- 安装 Visual Studio 2012。
- 安装更新 2。
- 从 SourceForge下载Boost。
- 解压到“C:\boost153”
- 使用管理员权限打开 Visual Studio 命令提示符。从开始菜单,它的
All Programs..Microsoft Visual Studio 2012..Visual Studio Tools..x64 Native Tools Command Prompt
. - 使用
cd c:\boost153
. - 运行
bootstrap.bat
。 - 运行
bjam.exe
。这将构建所有库。 - 可能会有一些警告,但您可以忽略这些。
当它在大约 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
这很重要,我们需要将这两条路径添加到任何新的 C++ 项目中。
- 创建一个新的 C++ 项目。
- 作为一对夫妇的步骤前指出,加
C:/boost153
给compiler include path
和C:\boost153\stage\lib
给linker library path
。 - 右键单击项目,选择
Properties
,选择Configuration Properties..VC++ Directories
。请参阅下面屏幕截图中粗体文本的两个部分): 让我们运行一个简单的程序,通过添加对
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; }
结果:
Hello, world!
More Answers
更多答案
- See Boost compiling with MSVC 11 (VS 2012).
- See Official Boost docs on compiling with Visual Studio under Windows.
- See Building Boost v1.64.
- 请参阅使用 MSVC 11 (VS 2012) 进行 Boost 编译。
- 请参阅有关在 Windows 下使用 Visual Studio 进行编译的官方 Boost 文档。
- 参见Building Boost v1.64。
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:
我设法按照以下步骤构建它:
- Open a Visual Studio command prompt. From the start menu it's: All Programs|Microsoft Visual Studio 11|Native x64 Command Prompt.
- Unzip boost_1_48_0.zip and set the working directory to boost_1_48_0
- run bootstrap.bat
- run bjam.exe
- 打开 Visual Studio 命令提示符。从开始菜单它是:所有程序|Microsoft Visual Studio 11|本机 x64 命令提示符。
- 解压 boost_1_48_0.zip 并将工作目录设置为 boost_1_48_0
- 运行 bootstrap.bat
- 运行 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.
回答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% 即可解决问题。