C++ 如何使用 Visual Studio 2015(企业)构建 boost 版本 1.58.0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31566807/
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 13:59:08  来源:igfitidea点击:

How to build boost Version 1.58.0 using Visual Studio 2015 (Enterprise)

c++boostvisual-studio-2015b2

提问by Vertexwahn

I like to build boost 1.58.0 using the (new) Visual Studio 2015 (Enterprise). In the past I proceeded in the following way:

我喜欢使用(新)Visual Studio 2015(企业)构建 boost 1.58.0。过去,我是按照以下方式进行的:

  1. Download boost 1.58.0 from www.boost.org
  2. Extract files (e.g. C:\thirdparty\vs2013\x64\boost_1_58_0)
  3. Start Visual Studio 2013 x64 command prompt (VS2013 x64 Native Tools Command Prompt)
  4. Change to boost directory (e.g. cd C:\thirdparty\vs2013\x64\boost_1_58_0)
  5. Execute .\bootstrap.bat
  6. Execute .\b2 -j8 --toolset=msvc-14.0 address-model=64 --build-type=complete stage
  7. b2 -j8 --toolset=msvc-12.0 address-model=64 --build-type=complete stage --with-python
  1. www.boost.org下载 boost 1.58.0
  2. 提取文件(例如C:\thirdparty\vs2013\x64\boost_1_58_0
  3. 启动 Visual Studio 2013 x64 命令提示符 ( VS2013 x64 Native Tools Command Prompt)
  4. 更改为 boost 目录(例如cd C:\thirdparty\vs2013\x64\boost_1_58_0
  5. 执行 .\bootstrap.bat
  6. 执行 .\b2 -j8 --toolset=msvc-14.0 address-model=64 --build-type=complete stage
  7. b2 -j8 --toolset=msvc-12.0 address-model=64 --build-type=complete stage --with-python

But in VS2015 there is not VS2015 command prompt.

但是在 VS2015 中没有 VS2015 命令提示符。

Also the vcvarsall.batis missing that I used sometimes to setup a VS2013 command prompt.

还有vcvarsall.bat我有时用来设置 VS2013 命令提示符的缺失。

How can I compile the source code of boost using VS2015?

如何使用VS2015编译boost的源代码?

采纳答案by Arnaud

I Tried to install Qt and I had the same issue: vcvarsall.bat was missing. In my case the problem was that I unchecked The Visual C++ Common Tools.

我尝试安装 Qt,但遇到了同样的问题:缺少 vcvarsall.bat。在我的情况下,问题是我取消选中 Visual C++ 通用工具。

I modified my VS 2015 installation and added the missing feature Common Tools for Visual C++ 2015:

我修改了我的 VS 2015 安装并添加了Visual C++ 2015缺少的功能Common Tools

enter image description here

在此处输入图片说明

After the modification, the File is in C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC

修改后文件在C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC

回答by Shital Shah

Unfortunately Boost documentationis quite verbose because it tries to take care of all OS and environments. Also, it skips over some time saving details. Here's quick steps specifically for VS2015 with Boost 1.61.

不幸的是,Boost 文档非常冗长,因为它试图处理所有操作系统和环境。此外,它会跳过一些节省时间的细节。这是专门针对 VS2015 和 Boost 1.61 的快速步骤。

First, let's understand that Boost is huge library with lots of contributors. Consequently, all of the Boost code is divided in to two parts: headers only libraries and header+cpp libraries. The former doesn't require compilation. You just include them and you are done. Later does require building. You typically don't need to worry about extra steps of building, although its good idea to just set everything up once.

首先,让我们了解 Boost 是一个巨大的库,有很多贡献者。因此,所有 Boost 代码分为两部分:仅标头库和标头 + cpp 库。前者不需要编译。您只需包含它们即可完成。后来确实需要构建。您通常不需要担心额外的构建步骤,尽管只设置一次是个好主意。

Using Boost Header Only Libraries

仅使用 Boost 标头库

  1. Download the Boost archivein 7z format and extract using 7Zip. The zip file is much bigger than 7z file and can take over 20 minutes to extract by Windows Explorer vs 5 minutes by 7Zip.
  2. Create folder c:\Program Files\boost. Copy extracted boost_1_61_0 folder in this folder. This exact path is not a requirement but we will use that here.
  3. In whatever VC++ project you want to use Boost, go to that project's right click Properties > C/C++ > General > Additional Include Directories and add path C:\Program Files\boost\boost_1_61_0 without quotes.
  1. 下载7z 格式的Boost 档案并使用 7Zip 解压缩。zip 文件比 7z 文件大得多,Windows 资源管理器提取需要 20 多分钟,而 7Zip 需要 5 分钟。
  2. 创建文件夹 c:\Program Files\boost。将提取的 boost_1_61_0 文件夹复制到此文件夹中。这个确切的路径不是必需的,但我们将在这里使用它。
  3. 在您想要使用 Boost 的任何 VC++ 项目中,转到该项目的右键单击 Properties > C/C++ > General > Additional Include Directories 并添加路径 C:\Program Files\boost\boost_1_61_0 不带引号。

Now you should be able to use most of the Boost libraries by using statement like #include <boost/thread/mutex.hpp>.

现在您应该能够通过使用像#include <boost/thread/mutex.hpp>.

Using Boost Header+CPP Libraries

使用 Boost Header+CPP 库

Examples of these are Boost.Chrono, Boost.Filesystem, Boost.GraphParallel, Boost.IOStreams, Boost.Locale, Boost.Regex, Boost.Thread, Boost.Systemetc. Unless you are using these libraries, following steps are not needed.

这些示例包括Boost.Chrono、Boost.Filesystem、Boost.GraphParallel、Boost.IOStreams、Boost.Locale、Boost.Regex、Boost.Thread、Boost.System等。除非您使用这些库,否则不需要执行以下步骤。

  1. First make sure you don't have Windows Driver Kit installed. If you have, uninstall it for now because most likely it has messed up include paths that will cause Boost's build script to fail.
  2. Invoke VS2015 x64 Native Tools Command Prompt as Administrator.
  3. CD to C:\Program Files\boost\boost_1_61_0 and then run bootstrap.bat.
  4. Run .\b2
  5. Run .\b2 variant=debug,release link=static runtime-link=static address-model=64
  6. Cut folder C:\Program Files\boost\boost_1_61_0\stage\lib and copy it to C:\Program Files\boost\boost_1_61_0\lib.
  7. For the VC++ Console project you want to use these libraries, right click Properties > Linker > General > Additional Library Directories and add path C:\Program Files\boost\boost_1_61_0\lib. For VC++ library projects you will find same setting in Properties > Librarian.
  1. 首先确保您没有安装 Windows Driver Kit。如果有,请暂时卸载它,因为它很可能已经弄乱了将导致 Boost 构建脚本失败的包含路径。
  2. 以管理员身份调用 VS2015 x64 本机工具命令提示符。
  3. CD 到 C:\Program Files\boost\boost_1_61_0 然后运行 ​​bootstrap.bat。
  4. 运行 .\b2
  5. 运行 .\b2 variant=debug,release link=static runtime-link=static address-model=64
  6. 剪切文件夹 C:\Program Files\boost\boost_1_61_0\stage\lib 并将其复制到 C:\Program Files\boost\boost_1_61_0\lib。
  7. 对于要使用这些库的 VC++ 控制台项目,右键单击“属性”>“链接器”>“常规”>“附加库目录”并添加路径 C:\Program Files\boost\boost_1_61_0\lib。对于 VC++ 库项目,您将在 Properties > Librarian 中找到相同的设置。

Now you are all set!

现在你已经准备好了!

Note: Original question about not finding command prompt is addressed by answer from @Arnaud. Above are more clarified steps for Boost installation also step #5 below for more detail on command prompt.

注意:@Arnaud 的回答解决了有关找不到命令提示符的原始问题。以上是 Boost 安装的更明确步骤,也是下面的第 5 步,以了解有关命令提示符的更多详细信息。

回答by Praveer Kumar

below are the steps

下面是步骤

1) Download library from below this site http://www.boost.org/

1) 从本网站http://www.boost.org/下载库

2) Unzip it.[I have extracted files at "F:\Internet-Downloads\boost_1_65_1" path]

2) 解压。[我已经在“F:\Internet-Downloads\boost_1_65_1”路径解压文件]

Unzip Boost library -Directory

解压 Boost 库 - 目录

3) Open "Developer Command Prompt for VS2015" as shown in the below snapshot.

3) 打开“VS2015 的开发人员命令提示符”,如下图所示。

open_Developer_Command_Prompt

open_Developer_Command_Prompt

4) Go to the directory in which you have extracted your files.

4) 转到解压缩文件的目录。

5) run bootstrap.bat file as shown in the below snapshot

5) 运行 bootstrap.bat 文件,如下图所示

Run Bootstrap.bat

运行 Bootstrap.bat

6) you will get installation information as shown in below snapshot

6) 您将获得如下图所示的安装信息

bootstrap.bat - result

bootstrap.bat - 结果

7) start VS2015, and create a test application as shown in below snapshot

7) 启动 VS2015,并创建一个测试应用程序,如下图所示

Test Application

测试申请

8) include boost directory in your project[Project Propertry->C/C++->General->Additional Include Directories]as shown in below snapshot

8) 在你的项目中包含 boost 目录[Project Properties->C/C++->General->Additional Include Directories]如下图所示

Include Boost Directory in testapp

在 testapp 中包含 Boost 目录

9) Run the application, add "_SCL_SECURE_NO_WARNINGS" in the preprocessor directory if you encounter with "error C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe ......" error.[Priject Property->C/C++->Preprocessor->Processor Definitions]

9) 运行应用程序,如果遇到“error C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe ......”错误,则在预处理器目录中添加“_SCL_SECURE_NO_WARNINGS”。[Priject Property- >C/C++->预处理器->处理器定义]

enter image description here

在此处输入图片说明

10 output:

10 输出:

output

输出

回答by DLyons

Use https://github.com/Microsoft/vcpkgfrom the VS Command Prompt.

从 VS 命令提示符使用https://github.com/Microsoft/vcpkg

回答by Vitaliy

To find and invoke VS2015 x64 Native Tools Command Prompt, just start typing "native" in Windows Start->Search programs and files text box. System should find command prompt

要查找和调用 VS2015 x64 本机工具命令提示符,只需在 Windows 开始->搜索程序和文件文本框中开始键入“本机”。系统应该找到命令提示符