如何在Visual Studio 2010中使用Boost ?

时间:2022-04-13 20:26:09

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

关于如何在Visual Studio 2010中的一个空项目中使用Boost库,有什么好的步骤?

13 个解决方案

#1


490  

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.

虽然内特的回答已经很好了,但我还是会按照要求在Visual Studio 2010中进行更多的扩展,包括在各种可选组件中编译的信息,这些组件需要外部库。

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.

如果您使用的是头文件库,那么您需要做的就是打开boost下载并设置环境变量。下面的指令仅为Visual Studio设置环境变量,而不是整个系统。注意,你只需要做一次。

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

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.

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

  1. Unarchive the latest version of boost (1.47.0 as of writing) into a directory of your choice (e.g. C:\boost_1_47_0).
  2. 将最新版本的boost(1.47.0)解压到您选择的目录中(例如:C:\boost_1_ 47_0)。
  3. Start the Visual Studio Command Prompt for the platform of your choice and navigate to where boost is.
  4. 启动Visual Studio命令提示,为您选择的平台并导航到boost所在的位置。
  5. Run: bootstrap.bat to build b2.exe (previously named bjam).
  6. 运行:引导。蝙蝠构建b2。exe(以前叫bjam)。
  7. Run b2:

    b2运行:

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

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

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

  1. Go through steps 2 - 6 from the set of instruction above to set the environment variables.
  2. 从上面的指令集到设置环境变量的步骤2 - 6。
  3. 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:\boost_1_47_0\stage\lib. Rename and move the directory first if you want to have x86 & x64 side by side (such as to <BOOST_PATH>\lib\x86 & <BOOST_PATH>\lib\x64).
  4. 编辑库目录一节,以包含您的boost库输出的路径。(上面的示例和说明的默认值是C:\boost _1_ 47_0\stage\lib。如果您想要将x86和x64并排放在一起(例如:to \lib\ lib\ lib\ lib\ lib / x64),请先重命名并移动目录。
  5. Repeat steps 2 - 6 for different platform of your choice if needed.
  6. 重复步骤2 - 6,如果需要的话,可以选择不同的平台。

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

如果您想要可选组件,那么您有更多的工作要做。这些都是:

  • Boost.IOStreams Bzip2 filters
  • 提振。iostream Bzip2过滤器
  • Boost.IOStreams Zlib filters
  • 提振。iostream Zlib过滤器
  • Boost.MPI
  • Boost.MPI
  • Boost.Python
  • Boost.Python
  • Boost.Regex ICU support
  • 提振。Regex ICU的支持

Boost.IOStreams Bzip2 filters:

提振。iostream Bzip2过滤器:

  1. Unarchive the latest version of bzip2 library (1.0.6 as of writing) source files into a directory of your choice (e.g. C:\bzip2-1.0.6).
  2. 将bzip2库的最新版本(将1.0.6写入文件)将源文件解压到您选择的目录中(例如,C:\bzip2-1.0.6)。
  3. Follow the second set of instructions above to build boost, but add in the option -sBZIP2_SOURCE="C:\bzip2-1.0.6" when running b2 in step 5.
  4. 遵循上面的第二组指令来构建boost,但是在步骤5中运行b2时,添加选项-sBZIP2_SOURCE="C:\bzip2-1.0.6"。

Boost.IOStreams Zlib filters

提振。iostream Zlib过滤器

  1. Unarchive the latest version of zlib library (1.2.5 as of writing) source files into a directory of your choice (e.g. C:\zlib-1.2.5).
  2. 将最新版本的zlib库(1.2.5编写)的源文件解压到您选择的目录中(例如,C:\zlib-1.2.5)。
  3. Follow the second set of instructions above to build boost, but add in the option -sZLIB_SOURCE="C:\zlib-1.2.5" when running b2 in step 5.
  4. 按照上面的第二组指令构建boost,但是在步骤5中运行b2时,添加选项-sZLIB_SOURCE="C:\zlib-1.2.5"。

Boost.MPI

Boost.MPI

  1. Install a MPI distribution such as Microsoft Compute Cluster Pack.
  2. 安装一个MPI分布,如Microsoft Compute Cluster Pack。
  3. Follow steps 1 - 3 from the second set of instructions above to build boost.
  4. 按照上面的第二组指令步骤1 - 3来构建boost。
  5. 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 ';').
  6. project-config编辑文件。在运行引导程序导致的目录 中阻塞。添加一行,使用mpi读取;(注意前面的空格)。
  7. 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.
  8. 从上面的第二组指令的其余步骤来构建boost。如果MPI安装的自动检测失败,那么您需要查找并修改适当的构建文件,以便在正确的位置查找MPI。

Boost.Python

Boost.Python

  1. Install a Python distribution such as ActiveState's ActivePython. Make sure the Python installation is in your PATH.
  2. 安装一个Python发行版,比如ActiveState的ActivePython。确保Python安装在您的路径中。
  3. 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 ';').

    要完全构建32位版本的库,需要32位Python,而64位版本则需要类似的操作。如果您已经安装了多个版本,那么您需要告诉b2哪里可以找到特定的版本,何时使用哪个版本。一种方法是编辑文件projectconfig。在运行引导程序导致的目录 中阻塞。在适合Python安装路径和版本的情况下,添加以下两行调整(注意前面的空格)。

    using python : 2.6 : C:\\Python\\Python26\\python ;

    使用python: 2.6:\\ python \\python \python;

    using python : 2.6 : C:\\Python\\Python26-x64\\python : : : <address-model>64 ;

    使用python: 2.6:\\ python \\Python26-x64\\python:: 64;

    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.

    请注意,这种显式的Python规范目前导致MPI构建失败。因此,如果您构建MPI,那么您需要使用和没有规范的独立构建来构建所有内容。

  4. Follow the second set of instructions above to build boost.

    按照上面的第二组指令来构建boost。

Boost.Regex ICU support

提振。Regex ICU的支持

  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. 将最新版本的ICU4C库(将其写入)源文件解压到您选择的目录中(如C:\ ICU4C -4_8)。
  3. Open the Visual Studio Solution in <ICU_PATH>\source\allinone.
  4. \source\allinone中打开Visual Studio解决方案。
  5. 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).
  6. 为您选择的平台构建所有的调试和发布配置。当调试和发布版本的输出位于相同的目录(这是默认行为)时,可能会出现一个问题,在Visual Studio 2010中构建ICU4C的最新版本。一个可能的解决方案是构建所有(调试版本),然后在第二个配置(例如版本构建)中进行重构。
  7. 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.
  8. 如果为x64构建,您将需要运行x64操作系统,因为有post构建步骤需要运行它所构建的64位应用程序。
  9. Optionally remove the source directory when you're done.
  10. 当您完成时,可以选择删除源目录。
  11. 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.
  12. 按照上面的第二组指令构建boost,但是在步骤5中运行b2时,添加选项-sICU_PATH="C:\icu4c-4_8"。

#2


146  

While the instructions on the Boost web site are helpful, here is a condensed version that also builds x64 libraries.

虽然Boost web站点上的说明是有用的,但这里有一个精简版,它还构建了x64库。

  • You only need to do this if you are using one of the libraries mentioned in section 3 of the instructions page. (E.g., to use Boost.Filesystem requires compilation.) If you are not using any of those, just unzip and go.
  • 如果您正在使用说明页第3节中提到的一个库,那么您只需要这样做。(例如,使用增加。文件系统需要编译。)如果你没有使用任何这些,只要解压缩就可以了。

Build the 32-bit libraries

This installs the Boost header files under C:\Boost\include\boost-(version), and the 32-bit libraries under C:\Boost\lib\i386. Note that the default location for the libraries is C:\Boost\lib but you’ll want to put them under an i386 directory if you plan to build for multiple architectures.

这将在C:\Boost\include\ Boost -(版本)中安装Boost头文件,以及C:\Boost\ i386下的32位库。请注意,库的默认位置是C:\Boost\lib,但是如果您计划构建多个架构,那么您将希望将它们放在i386目录下。

  1. Unzip Boost into a new directory.
  2. 解压缩到一个新目录。
  3. Start a 32-bit MSVC command prompt and change to the directory where Boost was unzipped.
  4. 启动一个32位的MSVC命令提示符,并将其更改为未压缩Boost的目录。
  5. Run: bootstrap
  6. 运行:引导
  7. Run: b2 toolset=msvc-12.0 --build-type=complete --libdir=C:\Boost\lib\i386 install
    • For Visual Studio 2012, use toolset=msvc-11.0
    • 对于Visual Studio 2012,使用toolset=msvc-11.0。
    • For Visual Studio 2010, use toolset=msvc-10.0
    • 对于Visual Studio 2010,使用toolset=msvc-10.0。
  8. 运行:b2 toolset=msvc-12.0——build-type=complete——libdir=C:\Boost\lib\i386安装Visual Studio 2012,使用toolset=msvc-11.0作为Visual Studio 2010,使用工具集=msvc-10.0。
  9. Add C:\Boost\include\boost-(version) to your include path.
  10. 添加C:\Boost\包括\Boost -(版本)到您的include路径。
  11. Add C:\Boost\lib\i386 to your libs path.
  12. 添加C:\Boost\lib\i386到您的libs路径。

Build the 64-bit libraries

This installs the Boost header files under C:\Boost\include\boost-(version), and the 64-bit libraries under C:\Boost\lib\x64. Note that the default location for the libraries is C:\Boost\lib but you’ll want to put them under an x64 directory if you plan to build for multiple architectures.

这将在C:\Boost\包括\Boost -(版本)中安装Boost头文件,以及在C:\Boost\lib\x64下的64位库。请注意,库的默认位置是C:\Boost\lib,但是如果您打算构建多个架构,那么您将希望将它们放在x64目录下。

  1. Unzip Boost into a new directory.
  2. 解压缩到一个新目录。
  3. Start a 64-bit MSVC command prompt and change to the directory where Boost was unzipped.
  4. 启动一个64位的MSVC命令提示符,并更改为解压缩的目录。
  5. Run: bootstrap
  6. 运行:引导
  7. Run: b2 toolset=msvc-12.0 --build-type=complete --libdir=C:\Boost\lib\x64 architecture=x86 address-model=64 install
    • For Visual Studio 2012, use toolset=msvc-11.0
    • 对于Visual Studio 2012,使用toolset=msvc-11.0。
    • For Visual Studio 2010, use toolset=msvc-10.0
    • 对于Visual Studio 2010,使用toolset=msvc-10.0。
  8. 运行:b2 toolset=msvc-12.0——build-type=complete——libdir=C:\Boost\ x64架构=x86 address-model=64安装Visual Studio 2012,使用toolset=msvc-11.0为Visual Studio 2010,使用工具集=msvc-10.0。
  9. Add C:\Boost\include\boost-(version) to your include path.
  10. 添加C:\Boost\包括\Boost -(版本)到您的include路径。
  11. Add C:\Boost\lib\x64 to your libs path.
  12. 添加C:\Boost\lib x64到您的libs路径。

#3


18  

You can also try -j%NUMBER_OF_PROCESSORS% as an argument it will use all your cores. Makes things super fast on my quad core.

您也可以使用-j% number_of_processor %作为参数,它将使用所有的内核。在我的quad core上做的非常快。

#4


13  

I could recommend the following trick: Create a special boost.props file

我可以推荐以下技巧:创建一个特殊的boost。道具文件

  1. Open the property manager
  2. 打开属性管理器
  3. Right click on your project node, and select 'Add new project property sheet'.
  4. 右键单击项目节点,并选择“添加新项目属性表”。
  5. Select a location and name your property sheet (e.g. c:\mystuff\boost.props)
  6. 选择一个位置,并命名你的属性表(例如,c:\mystuff\boost.道具)
  7. Modify the additional Include and Lib folders to the search path.
  8. 将附加的Include和Lib文件夹修改为搜索路径。

This procedure has the value that boost is included only in projects where you want to explicitly include it. When you have a new project that uses boost, do:

这个过程的值是boost只包含在您想要显式包含它的项目中。当你有一个使用boost的新项目时:

  1. Open the property manager.
  2. 打开物业经理。
  3. Right click on the project node, and select 'Add existing property sheet'.
  4. 右键单击项目节点,并选择“添加现有属性表”。
  5. Select the boost property sheet.
  6. 选择boost属性表。

EDIT (following edit from @jim-fred):

编辑(以下编辑@jim-fred):

The resulting boost.props file looks something like this...

由此产生的提振。道具文件看起来像这样…

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros">
    <BOOST_DIR>D:\boost_1_53_0\</BOOST_DIR>
  </PropertyGroup>
  <PropertyGroup>
    <IncludePath>$(BOOST_DIR);$(IncludePath)</IncludePath>
    <LibraryPath>$(BOOST_DIR)stage\lib\;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
</Project>

It contains a user macro for the location of the boost directory (in this case, D:\boost_1_53_0) and two other parameters: IncludePath and LibraryPath. A statement #include <boost/thread.hpp> would find thread.hpp in the appropriate directory (in this case, D:\boost_1_53_0\boost\thread.hpp). The 'stage\lib\' directory may change depending on the directory installed to.

它包含一个用于boost目录位置的用户宏(在本例中,D:\boost_1_ 53_0)和另外两个参数:IncludePath和LibraryPath。声明# include <刺激 线程。hpp> 会发现线程。hpp在适当的目录中(在本例中,D:\boost_1_53_0\boost\thread.hpp)。根据安装的目录,“stage\lib\”目录可能会发生更改。

This boost.props file could be located in the D:\boost_1_53_0\ directory.

这提振。道具文件可以位于D:\boost_1_ 53_0\目录。

#5


13  

What parts of Boost do you need? A lot of stuff is part of TR1 which is shipped with Visual Studio, so you could simply say, for example:

你需要哪些方面的刺激?很多东西都是TR1的一部分,它附带Visual Studio,所以你可以简单地说,例如:

#include <tr1/memory>

using std::tr1::shared_ptr;

According to James, this should also work (in C++0x):

根据James的说法,这应该也适用(在c++ 0x中):

#include <memory>

using std::shared_ptr;

#6


5  

Also a little note: If you want to reduce the compilation-time, you can add the flag

还有一点注意:如果您想要减少编译时,您可以添加标记。

-j2

j2

to run two parallel builds at the same time. This might reduce it to viewing one movie ;)

同时运行两个并行构建。这可能会减少看一部电影的效果;

#7


5  

This thread has been around a while, and I thought I'd add something about HOW to build Boost as fast as possible on your specific hardware.

这个线程已经有一段时间了,我想我应该添加一些关于如何在您的特定硬件上尽可能快地构建Boost的内容。

If you have a 4 or 6-core use -j5 or -j7 respectively. Certainly not the standard build nor -j2 unless you indeed have dual core.

如果您有一个4或6个核心的使用-j5或-j7。当然不是标准的构建,也不是-j2,除非你确实有双核心。

I'm running a Sandy Bridge Extreme with stock clocked 3930K (6-core) on my main station, but have a 2600k (4-core) on older backup box, and the trend is I get the best Boost compile times with N + 1 build processes where N is the number of physical cores. N+2 reaches a point of diminishing returns and the times go up.

在我的主站上,我运行的是一个带有clock 3930K(6核)的Sandy Bridge,但是在旧的备份盒上有一个2600k (4-core),而我的趋势是,在N + 1的构建过程中,我得到了最好的Boost编译时间,其中N是物理核心的数量。N+2达到了递减的点,时间也增加了。

Notes: Hyperthreading is enabled, 32GB RAM DDR3, Samsung 840 EVO SSD.

注:超线程启用,32GB RAM DDR3, Samsung 840 EVO SSD。

-j7 on 6-core (2 minutes and 51 seconds) (Win7 Ultimate x64)(Visual Studio 2013)

-j7 6芯(2分51秒)(Win7 Ultimate x64)(Visual Studio 2013)

PS C:\Boost\boost_1_56_0> measure-command { .\b2 -j7 --build-type=complete msvc stage }

Days              : 0
Hours             : 0
Minutes           : 2
Seconds           : 51
Milliseconds      : 128
Ticks             : 1711281830
TotalDays         : 0.0019806502662037
TotalHours        : 0.0475356063888889
TotalMinutes      : 2.85213638333333
TotalSeconds      : 171.128183
TotalMilliseconds : 171128.183

-j6 on 6-core (3 minutes and 2 seconds) (Win7 Ultimate x64)(Visual Studio 2013)

-j6 6芯(3分2秒)(Win7 Ultimate x64)(Visual Studio 2013)

PS C:\Boost\boost_1_56_0> measure-command { .\b2 -j6 --build-type=complete msvc stage }

Days              : 0
Hours             : 0
Minutes           : 3
Seconds           : 2
Milliseconds      : 809
Ticks             : 1828093904
TotalDays         : 0.00211584942592593
TotalHours        : 0.0507803862222222
TotalMinutes      : 3.04682317333333
TotalSeconds      : 182.8093904
TotalMilliseconds : 182809.3904

-j8 on 6-core (3 minutes and 17 seconds) (Win7 Ultimate x64)(Visual Studio 2013)

-j8 6芯(3分17秒)(Win7 Ultimate x64)(Visual Studio 2013)

PS C:\Boost\boost_1_56_0> measure-command { .\b2 -j8 --build-type=complete msvc stage }

Days              : 0
Hours             : 0
Minutes           : 3
Seconds           : 17
Milliseconds      : 652
Ticks             : 1976523915
TotalDays         : 0.00228764342013889
TotalHours        : 0.0549034420833333
TotalMinutes      : 3.294206525
TotalSeconds      : 197.6523915
TotalMilliseconds : 197652.3915

如何在Visual Studio 2010中使用Boost ?

Config

配置

Building the Boost C++ Libraries.


Performing configuration checks

    - 32-bit                   : yes (cached)
    - arm                      : no  (cached)
    - mips1                    : no  (cached)
    - power                    : no  (cached)
    - sparc                    : no  (cached)
    - x86                      : yes (cached)
    - has_icu builds           : no  (cached)
warning: Graph library does not contain MPI-based parallel components.
note: to enable them, add "using mpi ;" to your user-config.jam
    - zlib                     : no  (cached)
    - iconv (libc)             : no  (cached)
    - iconv (separate)         : no  (cached)
    - icu                      : no  (cached)
    - icu (lib64)              : no  (cached)
    - message-compiler         : yes (cached)
    - compiler-supports-ssse3  : yes (cached)
    - compiler-supports-avx2   : yes (cached)
    - gcc visibility           : no  (cached)
    - long double support      : yes (cached)
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
    - zlib                     : no  (cached)

I note the 64-bit build takes a bit longer, I need to do the same comparison for those and update.

我注意到64位构建需要更长的时间,我需要对它们进行相同的比较和更新。

#8


4  

Here is how I was able to use Boost:

下面是我如何使用Boost:

  1. Download and extract the zip version of Boost libraries.
  2. 下载并提取Boost库的zip版本。
  3. Run bootstrap.bat file and then run bjam.exe.
  4. 引导程序运行。bat文件,然后运行bjam.exe。
  5. Wait for roughly 30 minutes or so.
  6. 等待大约30分钟左右。
  7. Create a new project in Visual Studio.
  8. 在Visual Studio中创建一个新项目。
  9. Go to project-->properties-->Linker-->General-->Additional Library Directories and add boost/stage/lib directory to it.
  10. Go to project——>properties——>Linker——>General——>附加库目录,并添加boost/stage/lib目录。
  11. Go to project-->properties-->C/C++-->General-->Additional Include Directories and add boost directory to it.
  12. Go to project——>properties——>C/ c++——>General——>附加包括目录,并添加boost目录。

You will be able to build your project without any errors !

您将能够在没有任何错误的情况下构建您的项目!

#9


4  

Download boost from: http://www.boost.org/users/download/ e.g. by svn

下载boost: http://www.boost.org/users/download/,例如svn。

  • Windows -> tortoise (the simplest way)
  • Windows ->龟(最简单的方法)

After that : cmd -> go to boost directory ("D:\boostTrunk" - where You checkout or download and extract package): command : bootstrap

在此之后:cmd ->到boost目录(“D:\boostTrunk”——在那里您可以签出或下载和提取包):命令:bootstrap。

we created bjam.exe in ("D:\boostTrunk") After that : command : bjam toolset=msvc-10.0 variant=debug,release threading=multi link=static (It will take some time ~20min.)

我们创建了bjam。exe(“D:\boostTrunk”)之后:命令:bjam toolset=msvc-10.0变体=debug,release threading= multilink =static(需要一段时间~20min)。

After that: Open Visual studio 2010 -> create empty project -> go to project properties -> set:

在此之后:开放Visual studio 2010 ->创建空项目->到项目属性->设置:

如何在Visual Studio 2010中使用Boost ?

Paste this code and check if it is working?

粘贴这段代码并检查它是否正常工作?

#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/regex.hpp>

using namespace std;

struct Hello 
{
    Hello(){ 
        cout << "Hello constructor" << endl;
    }

    ~Hello(){
        cout << "Hello destructor" << endl;
        cin.get();
    }
};


int main(int argc, char**argv)
{
    //Boost regex, compiled library
    boost::regex regex("^(Hello|Bye) Boost$");
    boost::cmatch helloMatches;
    boost::regex_search("Hello Boost", helloMatches, regex);
    cout << "The word between () is: " << helloMatches[1] << endl;

    //Boost shared pointer, header only library
    boost::shared_ptr<Hello> sharedHello(new Hello);

    return 0;
}

Resources : https://www.youtube.com/watch?v=5AmwIwedTCM

资源:https://www.youtube.com/watch?v=5AmwIwedTCM

#10


3  

The Windows installers located here worked perfectly for me. I took the following steps:

这里的Windows安装程序非常适合我。我采取了以下步骤:

  1. Follow the installation wizard until finished.
  2. 跟随安装向导直到完成。
  3. Run visual studio.
  4. 运行visual studio。
  5. Create a new C++ project
  6. 创建一个新的c++项目。
  7. Open project properties (can be found by right-clicking the project name in the solution explorer)
  8. 打开项目属性(可以通过在解决方案资源管理器中右键单击项目名称找到)
  9. Under "C/C++ > General > Additional Include Directories" add the path where boost root directory. Default for my version was C:\local\boost_1_63_0. The number after "boost" is the version of boost.
  10. 在“C/ c++ >通用>附加包含目录”下面添加了boost根目录的路径。我的版本默认为C:\local\boost_1_ 63_0。“boost”之后的数字是boost的版本。
  11. In project properties, under "Linker > Additional Library Directories" add the directory for library files. Default for my version was C:\local\boost_1_63_0\lib64-msvc-14.0. The number after "lib" is related to the build target (32 bit or 64 bit in Visual Studio) and the number after "msvc" is related to the version of Visual Studio (14.0 is related to Visual Studio 2015, but I'm using it with the 2017 Visual Studio).
  12. 在项目属性中,在“Linker >附加库目录”下,为库文件添加目录。我的版本默认是C:\local\boost _1_ 63_0\lib64-msvc-14.0。“lib”后的数字与构建目标(Visual Studio中的32位或64位)相关,而“msvc”后的数字与Visual Studio的版本相关(14.0与Visual Studio 2015相关,但我正在使用它与2017 Visual Studio)。

Good luck!

好运!

#11


2  

A small addition to KTC's very informative main answer:

KTC的一个非常有用的主要回答是:

If you are using the free Visual Studio c++ 2010 Express, and managed to get that one to compile 64-bits binaries, and now want to use that to use a 64-bits version of the Boost libaries, you may end up with 32-bits libraries (your mileage may vary of course, but on my machine this is the sad case).

如果您使用的是免费的Visual Studio c++ 2010表达,并设法得到一个编译64位二进制文件,现在想用,使用64位版本的提升机库,你可能最终与32位库(当然,你的情况可能不同,但在我的机器上是可悲的情况)。

I could fix this using the following: inbetween the steps described above as

我可以使用下面的步骤来解决这个问题:在上面描述的步骤之间。

  1. Start a 32-bit MSVC command prompt and change to the directory where Boost was unzipped.
  2. 启动一个32位的MSVC命令提示符,并将其更改为未压缩Boost的目录。
  3. Run: bootstrap
  4. 运行:引导

I inserted a call to 'setenv' to set the environment. For a release build, the above steps become:

我给“setenv”插入了一个设置环境的调用。对于一个发布版本,上面的步骤变成:

  1. Start a 32-bit MSVC command prompt and change to the directory where Boost was unzipped.
  2. 启动一个32位的MSVC命令提示符,并将其更改为未压缩Boost的目录。
  3. Run: "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\setenv.cmd" /Release /x64
  4. 运行:“C:\ Program Files \ Microsoft Windows sdk \ \ v7.1 \ Bin \ setenv。cmd /释放/ x64
  5. Run: bootstrap
  6. 运行:引导

I found this info here: http://boost.2283326.n4.nabble.com/64-bit-with-VS-Express-again-td3044258.html

我在这里找到了这个信息:http://boost.2283326.n4.nabble.com/64-bit- with-vs-express/td3044258.html。

#12


1  

A minimalist example to get you started in Visual Studio:

一个简单的例子,让你开始在Visual Studio:

1.Download and unzip Boost from here.

1。从这里下载和解压。

2.Create a Visual Studio empty project, using an example boost library that does not require separate compilation:

2。创建一个Visual Studio空项目,使用一个不需要单独编译的示例boost库:

#include <iostream>
#include <boost/format.hpp>

using namespace std;  
using namespace boost;  

int main()  
{  
    unsigned int arr[5] = { 0x05, 0x04, 0xAA, 0x0F, 0x0D };  

    cout << format("%02X-%02X-%02X-%02X-%02X")  
            % arr[0]  
            % arr[1]  
            % arr[2]  
            % arr[3]  
            % arr[4]  
         << endl;  
}  

3.In your Visual Studio project properties set the Additional Include Directories:

3所示。在您的Visual Studio项目属性中设置额外的包含目录:

如何在Visual Studio 2010中使用Boost ?

For a very simple example:

举一个非常简单的例子:

How to Install the Boost Libraries in Visual Studio

如何在Visual Studio中安装Boost库?

If you don't want to use the entire boost library, just a subset:

如果你不想使用整个boost库,只需要一个子集:

Using a subset of the boost libraries in Windows

使用Windows中boost库的一个子集。

If you specifically want to now about the libraries that require compilation:

如果您现在特别想了解需要编译的库:

How to use the Boost compiled libraries in Windows

如何使用Windows中的Boost编译库?

#13


0  

In addition, there is something I find very useful. Use environment variables for your boost paths. (How to set environment variables in windows, link at bottom for 7,8,10) The BOOST_ROOT variable seems to be common place anymore and is set to the root path where you unzip boost.

此外,还有一些我觉得非常有用的东西。为您的boost路径使用环境变量。(如何在windows中设置环境变量,在底部连接7、8、10)BOOST_ROOT变量似乎已经是公共的地方了,并设置为您解压缩的根路径。

Then in Properties, c++, general, Additional Include Directories use $(BOOST_ROOT). Then if/when you move to a newer version of the boost library you can update your environment variable to point to this newer version. As more of your projects, use boost you will not have to update the 'Additional Include Directories' for all of them.

然后,在属性中,c++,一般,额外的包含目录使用$(BOOST_ROOT)。然后,如果您移动到boost库的新版本,您可以更新您的环境变量以指向这个新版本。随着您的项目的增多,使用boost您将不必为所有这些项目更新“额外的包含目录”。

You may also create a BOOST_LIB variable and point it to where the libs are staged. So likewise for the Linker->Additional Library Directories, you won't have to update projects. I have some old stuff built with vs10 and new stuff with vs14 so built both flavors of the boost lib to the same folder. So if I move a project from vs10 to vs14 I don't have to change the boost paths.

您还可以创建一个BOOST_LIB变量,并将其指向放置libs的地方。同样,对于Linker->额外的库目录,您不需要更新项目。我有一些用vs10构建的旧东西,以及vs14的新内容,所以将boost库的两种风格都构建到同一个文件夹中。因此,如果我将一个项目从vs10转移到vs14,我不需要改变boost路径。

NOTE: If you change an environment variable it will not suddenly work in an open VS project. VS loads variables on startup. So you will have to close VS and reopen it.

注意:如果您更改环境变量,它将不会突然在open VS项目中工作。在启动时加载变量。所以你必须关闭VS重新打开。

#1


490  

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.

虽然内特的回答已经很好了,但我还是会按照要求在Visual Studio 2010中进行更多的扩展,包括在各种可选组件中编译的信息,这些组件需要外部库。

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.

如果您使用的是头文件库,那么您需要做的就是打开boost下载并设置环境变量。下面的指令仅为Visual Studio设置环境变量,而不是整个系统。注意,你只需要做一次。

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

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.

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

  1. Unarchive the latest version of boost (1.47.0 as of writing) into a directory of your choice (e.g. C:\boost_1_47_0).
  2. 将最新版本的boost(1.47.0)解压到您选择的目录中(例如:C:\boost_1_ 47_0)。
  3. Start the Visual Studio Command Prompt for the platform of your choice and navigate to where boost is.
  4. 启动Visual Studio命令提示,为您选择的平台并导航到boost所在的位置。
  5. Run: bootstrap.bat to build b2.exe (previously named bjam).
  6. 运行:引导。蝙蝠构建b2。exe(以前叫bjam)。
  7. Run b2:

    b2运行:

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

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

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

  1. Go through steps 2 - 6 from the set of instruction above to set the environment variables.
  2. 从上面的指令集到设置环境变量的步骤2 - 6。
  3. 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:\boost_1_47_0\stage\lib. Rename and move the directory first if you want to have x86 & x64 side by side (such as to <BOOST_PATH>\lib\x86 & <BOOST_PATH>\lib\x64).
  4. 编辑库目录一节,以包含您的boost库输出的路径。(上面的示例和说明的默认值是C:\boost _1_ 47_0\stage\lib。如果您想要将x86和x64并排放在一起(例如:to \lib\ lib\ lib\ lib\ lib / x64),请先重命名并移动目录。
  5. Repeat steps 2 - 6 for different platform of your choice if needed.
  6. 重复步骤2 - 6,如果需要的话,可以选择不同的平台。

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

如果您想要可选组件,那么您有更多的工作要做。这些都是:

  • Boost.IOStreams Bzip2 filters
  • 提振。iostream Bzip2过滤器
  • Boost.IOStreams Zlib filters
  • 提振。iostream Zlib过滤器
  • Boost.MPI
  • Boost.MPI
  • Boost.Python
  • Boost.Python
  • Boost.Regex ICU support
  • 提振。Regex ICU的支持

Boost.IOStreams Bzip2 filters:

提振。iostream Bzip2过滤器:

  1. Unarchive the latest version of bzip2 library (1.0.6 as of writing) source files into a directory of your choice (e.g. C:\bzip2-1.0.6).
  2. 将bzip2库的最新版本(将1.0.6写入文件)将源文件解压到您选择的目录中(例如,C:\bzip2-1.0.6)。
  3. Follow the second set of instructions above to build boost, but add in the option -sBZIP2_SOURCE="C:\bzip2-1.0.6" when running b2 in step 5.
  4. 遵循上面的第二组指令来构建boost,但是在步骤5中运行b2时,添加选项-sBZIP2_SOURCE="C:\bzip2-1.0.6"。

Boost.IOStreams Zlib filters

提振。iostream Zlib过滤器

  1. Unarchive the latest version of zlib library (1.2.5 as of writing) source files into a directory of your choice (e.g. C:\zlib-1.2.5).
  2. 将最新版本的zlib库(1.2.5编写)的源文件解压到您选择的目录中(例如,C:\zlib-1.2.5)。
  3. Follow the second set of instructions above to build boost, but add in the option -sZLIB_SOURCE="C:\zlib-1.2.5" when running b2 in step 5.
  4. 按照上面的第二组指令构建boost,但是在步骤5中运行b2时,添加选项-sZLIB_SOURCE="C:\zlib-1.2.5"。

Boost.MPI

Boost.MPI

  1. Install a MPI distribution such as Microsoft Compute Cluster Pack.
  2. 安装一个MPI分布,如Microsoft Compute Cluster Pack。
  3. Follow steps 1 - 3 from the second set of instructions above to build boost.
  4. 按照上面的第二组指令步骤1 - 3来构建boost。
  5. 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 ';').
  6. project-config编辑文件。在运行引导程序导致的目录 中阻塞。添加一行,使用mpi读取;(注意前面的空格)。
  7. 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.
  8. 从上面的第二组指令的其余步骤来构建boost。如果MPI安装的自动检测失败,那么您需要查找并修改适当的构建文件,以便在正确的位置查找MPI。

Boost.Python

Boost.Python

  1. Install a Python distribution such as ActiveState's ActivePython. Make sure the Python installation is in your PATH.
  2. 安装一个Python发行版,比如ActiveState的ActivePython。确保Python安装在您的路径中。
  3. 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 ';').

    要完全构建32位版本的库,需要32位Python,而64位版本则需要类似的操作。如果您已经安装了多个版本,那么您需要告诉b2哪里可以找到特定的版本,何时使用哪个版本。一种方法是编辑文件projectconfig。在运行引导程序导致的目录 中阻塞。在适合Python安装路径和版本的情况下,添加以下两行调整(注意前面的空格)。

    using python : 2.6 : C:\\Python\\Python26\\python ;

    使用python: 2.6:\\ python \\python \python;

    using python : 2.6 : C:\\Python\\Python26-x64\\python : : : <address-model>64 ;

    使用python: 2.6:\\ python \\Python26-x64\\python:: 64;

    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.

    请注意,这种显式的Python规范目前导致MPI构建失败。因此,如果您构建MPI,那么您需要使用和没有规范的独立构建来构建所有内容。

  4. Follow the second set of instructions above to build boost.

    按照上面的第二组指令来构建boost。

Boost.Regex ICU support

提振。Regex ICU的支持

  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. 将最新版本的ICU4C库(将其写入)源文件解压到您选择的目录中(如C:\ ICU4C -4_8)。
  3. Open the Visual Studio Solution in <ICU_PATH>\source\allinone.
  4. \source\allinone中打开Visual Studio解决方案。
  5. 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).
  6. 为您选择的平台构建所有的调试和发布配置。当调试和发布版本的输出位于相同的目录(这是默认行为)时,可能会出现一个问题,在Visual Studio 2010中构建ICU4C的最新版本。一个可能的解决方案是构建所有(调试版本),然后在第二个配置(例如版本构建)中进行重构。
  7. 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.
  8. 如果为x64构建,您将需要运行x64操作系统,因为有post构建步骤需要运行它所构建的64位应用程序。
  9. Optionally remove the source directory when you're done.
  10. 当您完成时,可以选择删除源目录。
  11. 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.
  12. 按照上面的第二组指令构建boost,但是在步骤5中运行b2时,添加选项-sICU_PATH="C:\icu4c-4_8"。

#2


146  

While the instructions on the Boost web site are helpful, here is a condensed version that also builds x64 libraries.

虽然Boost web站点上的说明是有用的,但这里有一个精简版,它还构建了x64库。

  • You only need to do this if you are using one of the libraries mentioned in section 3 of the instructions page. (E.g., to use Boost.Filesystem requires compilation.) If you are not using any of those, just unzip and go.
  • 如果您正在使用说明页第3节中提到的一个库,那么您只需要这样做。(例如,使用增加。文件系统需要编译。)如果你没有使用任何这些,只要解压缩就可以了。

Build the 32-bit libraries

This installs the Boost header files under C:\Boost\include\boost-(version), and the 32-bit libraries under C:\Boost\lib\i386. Note that the default location for the libraries is C:\Boost\lib but you’ll want to put them under an i386 directory if you plan to build for multiple architectures.

这将在C:\Boost\include\ Boost -(版本)中安装Boost头文件,以及C:\Boost\ i386下的32位库。请注意,库的默认位置是C:\Boost\lib,但是如果您计划构建多个架构,那么您将希望将它们放在i386目录下。

  1. Unzip Boost into a new directory.
  2. 解压缩到一个新目录。
  3. Start a 32-bit MSVC command prompt and change to the directory where Boost was unzipped.
  4. 启动一个32位的MSVC命令提示符,并将其更改为未压缩Boost的目录。
  5. Run: bootstrap
  6. 运行:引导
  7. Run: b2 toolset=msvc-12.0 --build-type=complete --libdir=C:\Boost\lib\i386 install
    • For Visual Studio 2012, use toolset=msvc-11.0
    • 对于Visual Studio 2012,使用toolset=msvc-11.0。
    • For Visual Studio 2010, use toolset=msvc-10.0
    • 对于Visual Studio 2010,使用toolset=msvc-10.0。
  8. 运行:b2 toolset=msvc-12.0——build-type=complete——libdir=C:\Boost\lib\i386安装Visual Studio 2012,使用toolset=msvc-11.0作为Visual Studio 2010,使用工具集=msvc-10.0。
  9. Add C:\Boost\include\boost-(version) to your include path.
  10. 添加C:\Boost\包括\Boost -(版本)到您的include路径。
  11. Add C:\Boost\lib\i386 to your libs path.
  12. 添加C:\Boost\lib\i386到您的libs路径。

Build the 64-bit libraries

This installs the Boost header files under C:\Boost\include\boost-(version), and the 64-bit libraries under C:\Boost\lib\x64. Note that the default location for the libraries is C:\Boost\lib but you’ll want to put them under an x64 directory if you plan to build for multiple architectures.

这将在C:\Boost\包括\Boost -(版本)中安装Boost头文件,以及在C:\Boost\lib\x64下的64位库。请注意,库的默认位置是C:\Boost\lib,但是如果您打算构建多个架构,那么您将希望将它们放在x64目录下。

  1. Unzip Boost into a new directory.
  2. 解压缩到一个新目录。
  3. Start a 64-bit MSVC command prompt and change to the directory where Boost was unzipped.
  4. 启动一个64位的MSVC命令提示符,并更改为解压缩的目录。
  5. Run: bootstrap
  6. 运行:引导
  7. Run: b2 toolset=msvc-12.0 --build-type=complete --libdir=C:\Boost\lib\x64 architecture=x86 address-model=64 install
    • For Visual Studio 2012, use toolset=msvc-11.0
    • 对于Visual Studio 2012,使用toolset=msvc-11.0。
    • For Visual Studio 2010, use toolset=msvc-10.0
    • 对于Visual Studio 2010,使用toolset=msvc-10.0。
  8. 运行:b2 toolset=msvc-12.0——build-type=complete——libdir=C:\Boost\ x64架构=x86 address-model=64安装Visual Studio 2012,使用toolset=msvc-11.0为Visual Studio 2010,使用工具集=msvc-10.0。
  9. Add C:\Boost\include\boost-(version) to your include path.
  10. 添加C:\Boost\包括\Boost -(版本)到您的include路径。
  11. Add C:\Boost\lib\x64 to your libs path.
  12. 添加C:\Boost\lib x64到您的libs路径。

#3


18  

You can also try -j%NUMBER_OF_PROCESSORS% as an argument it will use all your cores. Makes things super fast on my quad core.

您也可以使用-j% number_of_processor %作为参数,它将使用所有的内核。在我的quad core上做的非常快。

#4


13  

I could recommend the following trick: Create a special boost.props file

我可以推荐以下技巧:创建一个特殊的boost。道具文件

  1. Open the property manager
  2. 打开属性管理器
  3. Right click on your project node, and select 'Add new project property sheet'.
  4. 右键单击项目节点,并选择“添加新项目属性表”。
  5. Select a location and name your property sheet (e.g. c:\mystuff\boost.props)
  6. 选择一个位置,并命名你的属性表(例如,c:\mystuff\boost.道具)
  7. Modify the additional Include and Lib folders to the search path.
  8. 将附加的Include和Lib文件夹修改为搜索路径。

This procedure has the value that boost is included only in projects where you want to explicitly include it. When you have a new project that uses boost, do:

这个过程的值是boost只包含在您想要显式包含它的项目中。当你有一个使用boost的新项目时:

  1. Open the property manager.
  2. 打开物业经理。
  3. Right click on the project node, and select 'Add existing property sheet'.
  4. 右键单击项目节点,并选择“添加现有属性表”。
  5. Select the boost property sheet.
  6. 选择boost属性表。

EDIT (following edit from @jim-fred):

编辑(以下编辑@jim-fred):

The resulting boost.props file looks something like this...

由此产生的提振。道具文件看起来像这样…

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros">
    <BOOST_DIR>D:\boost_1_53_0\</BOOST_DIR>
  </PropertyGroup>
  <PropertyGroup>
    <IncludePath>$(BOOST_DIR);$(IncludePath)</IncludePath>
    <LibraryPath>$(BOOST_DIR)stage\lib\;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
</Project>

It contains a user macro for the location of the boost directory (in this case, D:\boost_1_53_0) and two other parameters: IncludePath and LibraryPath. A statement #include <boost/thread.hpp> would find thread.hpp in the appropriate directory (in this case, D:\boost_1_53_0\boost\thread.hpp). The 'stage\lib\' directory may change depending on the directory installed to.

它包含一个用于boost目录位置的用户宏(在本例中,D:\boost_1_ 53_0)和另外两个参数:IncludePath和LibraryPath。声明# include <刺激 线程。hpp> 会发现线程。hpp在适当的目录中(在本例中,D:\boost_1_53_0\boost\thread.hpp)。根据安装的目录,“stage\lib\”目录可能会发生更改。

This boost.props file could be located in the D:\boost_1_53_0\ directory.

这提振。道具文件可以位于D:\boost_1_ 53_0\目录。

#5


13  

What parts of Boost do you need? A lot of stuff is part of TR1 which is shipped with Visual Studio, so you could simply say, for example:

你需要哪些方面的刺激?很多东西都是TR1的一部分,它附带Visual Studio,所以你可以简单地说,例如:

#include <tr1/memory>

using std::tr1::shared_ptr;

According to James, this should also work (in C++0x):

根据James的说法,这应该也适用(在c++ 0x中):

#include <memory>

using std::shared_ptr;

#6


5  

Also a little note: If you want to reduce the compilation-time, you can add the flag

还有一点注意:如果您想要减少编译时,您可以添加标记。

-j2

j2

to run two parallel builds at the same time. This might reduce it to viewing one movie ;)

同时运行两个并行构建。这可能会减少看一部电影的效果;

#7


5  

This thread has been around a while, and I thought I'd add something about HOW to build Boost as fast as possible on your specific hardware.

这个线程已经有一段时间了,我想我应该添加一些关于如何在您的特定硬件上尽可能快地构建Boost的内容。

If you have a 4 or 6-core use -j5 or -j7 respectively. Certainly not the standard build nor -j2 unless you indeed have dual core.

如果您有一个4或6个核心的使用-j5或-j7。当然不是标准的构建,也不是-j2,除非你确实有双核心。

I'm running a Sandy Bridge Extreme with stock clocked 3930K (6-core) on my main station, but have a 2600k (4-core) on older backup box, and the trend is I get the best Boost compile times with N + 1 build processes where N is the number of physical cores. N+2 reaches a point of diminishing returns and the times go up.

在我的主站上,我运行的是一个带有clock 3930K(6核)的Sandy Bridge,但是在旧的备份盒上有一个2600k (4-core),而我的趋势是,在N + 1的构建过程中,我得到了最好的Boost编译时间,其中N是物理核心的数量。N+2达到了递减的点,时间也增加了。

Notes: Hyperthreading is enabled, 32GB RAM DDR3, Samsung 840 EVO SSD.

注:超线程启用,32GB RAM DDR3, Samsung 840 EVO SSD。

-j7 on 6-core (2 minutes and 51 seconds) (Win7 Ultimate x64)(Visual Studio 2013)

-j7 6芯(2分51秒)(Win7 Ultimate x64)(Visual Studio 2013)

PS C:\Boost\boost_1_56_0> measure-command { .\b2 -j7 --build-type=complete msvc stage }

Days              : 0
Hours             : 0
Minutes           : 2
Seconds           : 51
Milliseconds      : 128
Ticks             : 1711281830
TotalDays         : 0.0019806502662037
TotalHours        : 0.0475356063888889
TotalMinutes      : 2.85213638333333
TotalSeconds      : 171.128183
TotalMilliseconds : 171128.183

-j6 on 6-core (3 minutes and 2 seconds) (Win7 Ultimate x64)(Visual Studio 2013)

-j6 6芯(3分2秒)(Win7 Ultimate x64)(Visual Studio 2013)

PS C:\Boost\boost_1_56_0> measure-command { .\b2 -j6 --build-type=complete msvc stage }

Days              : 0
Hours             : 0
Minutes           : 3
Seconds           : 2
Milliseconds      : 809
Ticks             : 1828093904
TotalDays         : 0.00211584942592593
TotalHours        : 0.0507803862222222
TotalMinutes      : 3.04682317333333
TotalSeconds      : 182.8093904
TotalMilliseconds : 182809.3904

-j8 on 6-core (3 minutes and 17 seconds) (Win7 Ultimate x64)(Visual Studio 2013)

-j8 6芯(3分17秒)(Win7 Ultimate x64)(Visual Studio 2013)

PS C:\Boost\boost_1_56_0> measure-command { .\b2 -j8 --build-type=complete msvc stage }

Days              : 0
Hours             : 0
Minutes           : 3
Seconds           : 17
Milliseconds      : 652
Ticks             : 1976523915
TotalDays         : 0.00228764342013889
TotalHours        : 0.0549034420833333
TotalMinutes      : 3.294206525
TotalSeconds      : 197.6523915
TotalMilliseconds : 197652.3915

如何在Visual Studio 2010中使用Boost ?

Config

配置

Building the Boost C++ Libraries.


Performing configuration checks

    - 32-bit                   : yes (cached)
    - arm                      : no  (cached)
    - mips1                    : no  (cached)
    - power                    : no  (cached)
    - sparc                    : no  (cached)
    - x86                      : yes (cached)
    - has_icu builds           : no  (cached)
warning: Graph library does not contain MPI-based parallel components.
note: to enable them, add "using mpi ;" to your user-config.jam
    - zlib                     : no  (cached)
    - iconv (libc)             : no  (cached)
    - iconv (separate)         : no  (cached)
    - icu                      : no  (cached)
    - icu (lib64)              : no  (cached)
    - message-compiler         : yes (cached)
    - compiler-supports-ssse3  : yes (cached)
    - compiler-supports-avx2   : yes (cached)
    - gcc visibility           : no  (cached)
    - long double support      : yes (cached)
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
    - zlib                     : no  (cached)

I note the 64-bit build takes a bit longer, I need to do the same comparison for those and update.

我注意到64位构建需要更长的时间,我需要对它们进行相同的比较和更新。

#8


4  

Here is how I was able to use Boost:

下面是我如何使用Boost:

  1. Download and extract the zip version of Boost libraries.
  2. 下载并提取Boost库的zip版本。
  3. Run bootstrap.bat file and then run bjam.exe.
  4. 引导程序运行。bat文件,然后运行bjam.exe。
  5. Wait for roughly 30 minutes or so.
  6. 等待大约30分钟左右。
  7. Create a new project in Visual Studio.
  8. 在Visual Studio中创建一个新项目。
  9. Go to project-->properties-->Linker-->General-->Additional Library Directories and add boost/stage/lib directory to it.
  10. Go to project——>properties——>Linker——>General——>附加库目录,并添加boost/stage/lib目录。
  11. Go to project-->properties-->C/C++-->General-->Additional Include Directories and add boost directory to it.
  12. Go to project——>properties——>C/ c++——>General——>附加包括目录,并添加boost目录。

You will be able to build your project without any errors !

您将能够在没有任何错误的情况下构建您的项目!

#9


4  

Download boost from: http://www.boost.org/users/download/ e.g. by svn

下载boost: http://www.boost.org/users/download/,例如svn。

  • Windows -> tortoise (the simplest way)
  • Windows ->龟(最简单的方法)

After that : cmd -> go to boost directory ("D:\boostTrunk" - where You checkout or download and extract package): command : bootstrap

在此之后:cmd ->到boost目录(“D:\boostTrunk”——在那里您可以签出或下载和提取包):命令:bootstrap。

we created bjam.exe in ("D:\boostTrunk") After that : command : bjam toolset=msvc-10.0 variant=debug,release threading=multi link=static (It will take some time ~20min.)

我们创建了bjam。exe(“D:\boostTrunk”)之后:命令:bjam toolset=msvc-10.0变体=debug,release threading= multilink =static(需要一段时间~20min)。

After that: Open Visual studio 2010 -> create empty project -> go to project properties -> set:

在此之后:开放Visual studio 2010 ->创建空项目->到项目属性->设置:

如何在Visual Studio 2010中使用Boost ?

Paste this code and check if it is working?

粘贴这段代码并检查它是否正常工作?

#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/regex.hpp>

using namespace std;

struct Hello 
{
    Hello(){ 
        cout << "Hello constructor" << endl;
    }

    ~Hello(){
        cout << "Hello destructor" << endl;
        cin.get();
    }
};


int main(int argc, char**argv)
{
    //Boost regex, compiled library
    boost::regex regex("^(Hello|Bye) Boost$");
    boost::cmatch helloMatches;
    boost::regex_search("Hello Boost", helloMatches, regex);
    cout << "The word between () is: " << helloMatches[1] << endl;

    //Boost shared pointer, header only library
    boost::shared_ptr<Hello> sharedHello(new Hello);

    return 0;
}

Resources : https://www.youtube.com/watch?v=5AmwIwedTCM

资源:https://www.youtube.com/watch?v=5AmwIwedTCM

#10


3  

The Windows installers located here worked perfectly for me. I took the following steps:

这里的Windows安装程序非常适合我。我采取了以下步骤:

  1. Follow the installation wizard until finished.
  2. 跟随安装向导直到完成。
  3. Run visual studio.
  4. 运行visual studio。
  5. Create a new C++ project
  6. 创建一个新的c++项目。
  7. Open project properties (can be found by right-clicking the project name in the solution explorer)
  8. 打开项目属性(可以通过在解决方案资源管理器中右键单击项目名称找到)
  9. Under "C/C++ > General > Additional Include Directories" add the path where boost root directory. Default for my version was C:\local\boost_1_63_0. The number after "boost" is the version of boost.
  10. 在“C/ c++ >通用>附加包含目录”下面添加了boost根目录的路径。我的版本默认为C:\local\boost_1_ 63_0。“boost”之后的数字是boost的版本。
  11. In project properties, under "Linker > Additional Library Directories" add the directory for library files. Default for my version was C:\local\boost_1_63_0\lib64-msvc-14.0. The number after "lib" is related to the build target (32 bit or 64 bit in Visual Studio) and the number after "msvc" is related to the version of Visual Studio (14.0 is related to Visual Studio 2015, but I'm using it with the 2017 Visual Studio).
  12. 在项目属性中,在“Linker >附加库目录”下,为库文件添加目录。我的版本默认是C:\local\boost _1_ 63_0\lib64-msvc-14.0。“lib”后的数字与构建目标(Visual Studio中的32位或64位)相关,而“msvc”后的数字与Visual Studio的版本相关(14.0与Visual Studio 2015相关,但我正在使用它与2017 Visual Studio)。

Good luck!

好运!

#11


2  

A small addition to KTC's very informative main answer:

KTC的一个非常有用的主要回答是:

If you are using the free Visual Studio c++ 2010 Express, and managed to get that one to compile 64-bits binaries, and now want to use that to use a 64-bits version of the Boost libaries, you may end up with 32-bits libraries (your mileage may vary of course, but on my machine this is the sad case).

如果您使用的是免费的Visual Studio c++ 2010表达,并设法得到一个编译64位二进制文件,现在想用,使用64位版本的提升机库,你可能最终与32位库(当然,你的情况可能不同,但在我的机器上是可悲的情况)。

I could fix this using the following: inbetween the steps described above as

我可以使用下面的步骤来解决这个问题:在上面描述的步骤之间。

  1. Start a 32-bit MSVC command prompt and change to the directory where Boost was unzipped.
  2. 启动一个32位的MSVC命令提示符,并将其更改为未压缩Boost的目录。
  3. Run: bootstrap
  4. 运行:引导

I inserted a call to 'setenv' to set the environment. For a release build, the above steps become:

我给“setenv”插入了一个设置环境的调用。对于一个发布版本,上面的步骤变成:

  1. Start a 32-bit MSVC command prompt and change to the directory where Boost was unzipped.
  2. 启动一个32位的MSVC命令提示符,并将其更改为未压缩Boost的目录。
  3. Run: "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\setenv.cmd" /Release /x64
  4. 运行:“C:\ Program Files \ Microsoft Windows sdk \ \ v7.1 \ Bin \ setenv。cmd /释放/ x64
  5. Run: bootstrap
  6. 运行:引导

I found this info here: http://boost.2283326.n4.nabble.com/64-bit-with-VS-Express-again-td3044258.html

我在这里找到了这个信息:http://boost.2283326.n4.nabble.com/64-bit- with-vs-express/td3044258.html。

#12


1  

A minimalist example to get you started in Visual Studio:

一个简单的例子,让你开始在Visual Studio:

1.Download and unzip Boost from here.

1。从这里下载和解压。

2.Create a Visual Studio empty project, using an example boost library that does not require separate compilation:

2。创建一个Visual Studio空项目,使用一个不需要单独编译的示例boost库:

#include <iostream>
#include <boost/format.hpp>

using namespace std;  
using namespace boost;  

int main()  
{  
    unsigned int arr[5] = { 0x05, 0x04, 0xAA, 0x0F, 0x0D };  

    cout << format("%02X-%02X-%02X-%02X-%02X")  
            % arr[0]  
            % arr[1]  
            % arr[2]  
            % arr[3]  
            % arr[4]  
         << endl;  
}  

3.In your Visual Studio project properties set the Additional Include Directories:

3所示。在您的Visual Studio项目属性中设置额外的包含目录:

如何在Visual Studio 2010中使用Boost ?

For a very simple example:

举一个非常简单的例子:

How to Install the Boost Libraries in Visual Studio

如何在Visual Studio中安装Boost库?

If you don't want to use the entire boost library, just a subset:

如果你不想使用整个boost库,只需要一个子集:

Using a subset of the boost libraries in Windows

使用Windows中boost库的一个子集。

If you specifically want to now about the libraries that require compilation:

如果您现在特别想了解需要编译的库:

How to use the Boost compiled libraries in Windows

如何使用Windows中的Boost编译库?

#13


0  

In addition, there is something I find very useful. Use environment variables for your boost paths. (How to set environment variables in windows, link at bottom for 7,8,10) The BOOST_ROOT variable seems to be common place anymore and is set to the root path where you unzip boost.

此外,还有一些我觉得非常有用的东西。为您的boost路径使用环境变量。(如何在windows中设置环境变量,在底部连接7、8、10)BOOST_ROOT变量似乎已经是公共的地方了,并设置为您解压缩的根路径。

Then in Properties, c++, general, Additional Include Directories use $(BOOST_ROOT). Then if/when you move to a newer version of the boost library you can update your environment variable to point to this newer version. As more of your projects, use boost you will not have to update the 'Additional Include Directories' for all of them.

然后,在属性中,c++,一般,额外的包含目录使用$(BOOST_ROOT)。然后,如果您移动到boost库的新版本,您可以更新您的环境变量以指向这个新版本。随着您的项目的增多,使用boost您将不必为所有这些项目更新“额外的包含目录”。

You may also create a BOOST_LIB variable and point it to where the libs are staged. So likewise for the Linker->Additional Library Directories, you won't have to update projects. I have some old stuff built with vs10 and new stuff with vs14 so built both flavors of the boost lib to the same folder. So if I move a project from vs10 to vs14 I don't have to change the boost paths.

您还可以创建一个BOOST_LIB变量,并将其指向放置libs的地方。同样,对于Linker->额外的库目录,您不需要更新项目。我有一些用vs10构建的旧东西,以及vs14的新内容,所以将boost库的两种风格都构建到同一个文件夹中。因此,如果我将一个项目从vs10转移到vs14,我不需要改变boost路径。

NOTE: If you change an environment variable it will not suddenly work in an open VS project. VS loads variables on startup. So you will have to close VS and reopen it.

注意:如果您更改环境变量,它将不会突然在open VS项目中工作。在启动时加载变量。所以你必须关闭VS重新打开。