如何在 Visual Studio 2010 中使用 Boost [英] How to use Boost in Visual Studio 2010

查看:39
本文介绍了如何在 Visual Studio 2010 中使用 Boost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于如何在 Visual Studio 的空项目中使用 Boost 库的分步说明是什么?

What is a good step by step explanation on how to use the Boost library in an empty project in Visual Studio?

推荐答案

虽然 Nate 的回答 已经很不错了,我将根据要求更具体地针对 Visual Studio 2010 对其进行扩展,并包括有关在需要外部库的各种可选组件中进行编译的信息.

While Nate's answer is pretty good already, I'm going to expand on it more specifically for Visual Studio 2010 as requested, and include information on compiling in the various optional components which requires external libraries.

如果您只使用头文件库,那么您需要做的就是解压缩 boost 下载并设置环境变量.下面的说明仅为 Visual Studio 设置环境变量,而不是整个系统.请注意,您只需执行一次.

If you are using headers only libraries, then all you need to do is to unarchive the boost download and set up the environment variables. The instruction below set the environment variables for Visual Studio only, and not across the system as a whole. Note you only have to do it once.

  1. 将最新版本的 boost(编写时为 1.47.0)解压缩到您选择的目录(例如 C:oost_1_47_0).
  2. 在 Visual Studio 中创建一个新的空项目.
  3. 打开 Property Manager 并展开您选择的平台的配置之一.
  4. 选择 &右键单击Microsoft.Cpp..user,然后选择Properties 打开属性页进行编辑.
  5. 选择左侧的 VC++ 目录.
  6. 编辑 Include Directories 部分以包含 boost 源文件的路径.
  7. 如果需要,请针对您选择的不同平台重复步骤 3 - 6.
  1. Unarchive the latest version of boost (1.47.0 as of writing) into a directory of your choice (e.g. C:oost_1_47_0).
  2. Create a new empty project in Visual Studio.
  3. Open the Property Manager and expand one of the configuration for the platform of your choice.
  4. Select & right click Microsoft.Cpp.<Platform>.user, and select Properties to open the Property Page for edit.
  5. Select VC++ Directories on the left.
  6. Edit the Include Directories section to include the path to your boost source files.
  7. Repeat steps 3 - 6 for different platform of your choice if needed.

如果你想使用 boost 需要构建的部分,但没有需要外部依赖的特性,那么构建它是相当简单的.

If you want to use the part of boost that require building, but none of the features that requires external dependencies, then building it is fairly simple.

  1. 将最新版本的 boost(编写时为 1.47.0)解压缩到您选择的目录(例如 C:oost_1_47_0).
  2. 为您选择的平台启动 Visual Studio 命令提示符并导航到 boost 所在的位置.
  3. 运行:bootstrap.bat 以构建 b2.exe(以前称为 bjam).
  4. 运行 b2:

  1. Unarchive the latest version of boost (1.47.0 as of writing) into a directory of your choice (e.g. C:oost_1_47_0).
  2. Start the Visual Studio Command Prompt for the platform of your choice and navigate to where boost is.
  3. Run: bootstrap.bat to build b2.exe (previously named bjam).
  4. Run b2:

  • Win32: b2 --toolset=msvc-10.0 --build-type=complete stage ;
  • x64: b2 --toolset=msvc-10.0 --build-type=complete architecture=x86 address-model=64 stage

去散步/看电影或 2/....

Go for a walk / watch a movie or 2 / ....

  1. 按照上述指令集执行步骤 2 - 6 以设置环境变量.
  2. 编辑Library Directories 部分以包含boost 库输出的路径.(上述示例和说明的默认值是 C:oost_1_47_0stagelib.如果您想让 x86 和 x64 并排放置(例如 <代码>libx86 & libx64).
  3. 如果需要,请针对您选择的不同平台重复步骤 2 - 6.
  1. Go through steps 2 - 6 from the set of instruction above to set the environment variables.
  2. Edit the Library Directories section to include the path to your boost libraries output. (The default for the example and instructions above would be C:oost_1_47_0stagelib. Rename and move the directory first if you want to have x86 & x64 side by side (such as to <BOOST_PATH>libx86 & <BOOST_PATH>libx64).
  3. Repeat steps 2 - 6 for different platform of your choice if needed.

如果您想要可选组件,那么您还有更多工作要做.它们是:

If you want the optional components, then you have more work to do. These are:

  • Boost.IOStreams Bzip2 过滤器
  • Boost.IOStreams Zlib 过滤器
  • Boost.MPI
  • Boost.Python
  • Boost.Regex ICU 支持

Boost.IOStreams Bzip2 过滤器:

Boost.IOStreams Bzip2 filters:

  1. 将最新版本的 bzip2 库(编写时为 1.0.6)源文件解压缩到您选择的目录中(例如 C:zip2-1.0.6).
  2. 按照上述第二组说明构建 boost,但在第 5 步中运行 b2 时添加选项 -sBZIP2_SOURCE="C:zip2-1.0.6".

Boost.IOStreams Zlib 过滤器

Boost.IOStreams Zlib filters

  1. 将最新版本的 zlib 库(编写时为 1.2.5)源文件解压缩到您选择的目录中(例如 C:zlib-1.2.5).
  2. 按照上述第二组说明构建 boost,但在第 5 步中运行 b2 时添加选项 -sZLIB_SOURCE="C:zlib-1.2.5".

Boost.MPI

  1. 安装 MPI 发行版,例如 Microsoft Compute Cluster Pack.
  2. 按照上述第二组说明中的步骤 1 - 3 来构建提升.
  3. 编辑目录 中的文件 project-config.jam,这是运行引导程序产生的.添加一行读取using mpi ;(注意';'之前的空格).
  4. 按照上述第二组说明中的其余步骤来构建提升.如果自动检测 MPI 安装失败,则您需要查找并修改相应的构建文件以在正确的位置查找 MPI.
  1. Install a MPI distribution such as Microsoft Compute Cluster Pack.
  2. Follow steps 1 - 3 from the second set of instructions above to build boost.
  3. Edit the file project-config.jam in the directory <BOOST_PATH> that resulted from running bootstrap. Add in a line that read using mpi ; (note the space before the ';').
  4. Follow the rest of the steps from the second set of instructions above to build boost. If auto-detection of the MPI installation fail, then you'll need to look for and modify the appropriate build file to look for MPI in the right place.

Boost.Python

Boost.Python

  1. 安装 Python 发行版,例如 ActiveState 的 ActivePython.确保 Python 安装在您的 PATH 中.
  2. 要完全构建 32 位版本的库需要 32 位 Python,对于 64 位版本也是如此.如果出于这种原因安装了多个版本,则需要告诉 b2 在哪里可以找到特定版本以及何时使用哪个版本.一种方法是编辑目录 <BOOST_PATH> 中的文件 project-config.jam,这是运行引导程序产生的.添加以下两行,根据您的 Python 安装路径进行调整 &版本(注意';'前的空格).

  1. Install a Python distribution such as ActiveState's ActivePython. Make sure the Python installation is in your PATH.
  2. To completely built the 32-bits version of the library requires 32-bits Python, and similarly for the 64-bits version. If you have multiple versions installed for such reason, you'll need to tell b2 where to find specific version and when to use which one. One way to do that would be to edit the file project-config.jam in the directory <BOOST_PATH> that resulted from running bootstrap. Add in the following two lines adjusting as appropriate for your Python installation paths & versions (note the space before the ';').

使用 python : 2.6 : C:\Python\Python26\python ;

using python : 2.6 : C:\Python\Python26-x64\python : : 64 ;

请注意,目前这种明确的 Python 规范会导致 MPI 构建失败.因此,如果您还要构建 MPI,则需要使用规范和不使用规范进行一些单独的构建,以构建所有内容.

Do note that such explicit Python specification currently cause MPI build to fail. So you'll need to do some separate building with and without specification to build everything if you're building MPI as well.

按照上面的第二组说明来构建提升.

Follow the second set of instructions above to build boost.

Boost.Regex ICU 支持

Boost.Regex ICU support

  1. 将最新版本的 ICU4C 库(编写时为 4.8)源文件解压缩到您选择的目录中(例如 C:icu4c-4_8).
  2. sourceallinone 中打开 Visual Studio 解决方案.
  3. Build All 用于调试和调试为您选择的平台发布配置.使用 Visual Studio 2010 构建最新版本的 ICU4C 时,可能会出现问题用于调试和release build 位于同一目录中(这是默认行为).一种可能的解决方法是执行全部构建(例如调试构建),然后在第二个配置(例如发布构建)中执行全部重建.
  4. 如果为 x64 构建,您将需要运行 x64 操作系统,因为构建后步骤涉及运行它正在构建的一些 64 位应用程序.
  5. 完成后可以选择删除源目录.
  6. 按照上述第二组说明构建 boost,但在第 5 步中运行 b2 时添加选项 -sICU_PATH="C:icu4c-4_8".
  1. Unarchive the latest version of ICU4C library (4.8 as of writing) source file into a directory of your choice (e.g. C:icu4c-4_8).
  2. Open the Visual Studio Solution in <ICU_PATH>sourceallinone.
  3. Build All for both debug & release configuration for the platform of your choice. There can be a problem building recent releases of ICU4C with Visual Studio 2010 when the output for both debug & release build are in the same directory (which is the default behaviour). A possible workaround is to do a Build All (of debug build say) and then do a Rebuild all in the 2nd configuration (e.g. release build).
  4. If building for x64, you'll need to be running x64 OS as there's post build steps that involves running some of the 64-bits application that it's building.
  5. Optionally remove the source directory when you're done.
  6. Follow the second set of instructions above to build boost, but add in the option -sICU_PATH="C:icu4c-4_8" when running b2 in step 5.

这篇关于如何在 Visual Studio 2010 中使用 Boost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆