关于如何在Visual Studio的空项目中使用Boost库的一步一步的解释是什么?


当前回答

下面是我使用Boost的方法:

下载并解压zip版本的Boost库。 运行bootstrap.bat文件,然后运行bjam.exe。 等待大约30分钟左右。 在Visual Studio中创建一个新项目。 转到项目——>属性——>连接器——>通用——>附加库目录,并将boost/stage/lib目录添加到其中。 转到项目——>属性——>C/ c++——>通用——>附加包括目录并添加boost目录。

您将能够毫无错误地构建您的项目!

其他回答

你需要Boost的哪些部分?很多东西都是TR1的一部分,它是随Visual Studio一起发布的,所以你可以简单地说,例如:

#include <tr1/memory>

using std::tr1::shared_ptr;

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

#include <memory>

using std::shared_ptr;

下面是我使用Boost的方法:

下载并解压zip版本的Boost库。 运行bootstrap.bat文件,然后运行bjam.exe。 等待大约30分钟左右。 在Visual Studio中创建一个新项目。 转到项目——>属性——>连接器——>通用——>附加库目录,并将boost/stage/lib目录添加到其中。 转到项目——>属性——>C/ c++——>通用——>附加包括目录并添加boost目录。

您将能够毫无错误地构建您的项目!

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

Follow the installation wizard until finished. Run visual studio. Create a new C++ project Open project properties (can be found by right-clicking the project name in the solution explorer) 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. 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).

好运!

我可以推荐以下技巧:创造一种特殊的刺激。道具文件

打开物业管理 右键单击项目节点,选择“添加新项目属性表”。 选择一个位置并命名您的属性表(例如:c:\mystuff\boost.props) 将附加的Include和Lib文件夹修改为搜索路径。

此过程的价值是仅在希望显式包含boost的项目中包含它。当你有一个使用boost的新项目时,请:

打开物业管理器。 右键单击项目节点,并选择“添加现有属性表”。 选择boost属性表。

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

由此产生的推动力。道具文件看起来像这样…

<?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>

它包含一个用于boost目录位置的用户宏(在本例中为D:\boost_1_53_0)和另外两个参数:IncludePath和LibraryPath。语句#include <boost/thread.hpp>将在适当的目录中找到thread.hpp(在本例中为D:\boost_1_53_0\boost\thread.hpp)。'stage\lib\'目录可能会根据安装到的目录而改变。

这提振。props文件可以位于D:\boost_1_53_0\目录中。

在KTC非常翔实的主要回答中补充一点:

如果您正在使用免费的Visual Studio c++ 2010 Express,并设法获得了一个编译64位二进制文件的程序,现在想使用它来使用64位版本的Boost库,那么您最终可能会使用32位程序库(当然,您的情况可能有所不同,但在我的机器上这是令人遗憾的情况)。

我可以使用以下方法来修复这个问题:在上述步骤之间

启动32位MSVC命令提示符,并切换到解压缩Boost的目录。 运行:引导

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

启动32位MSVC命令提示符,并切换到解压缩Boost的目录。 运行:"C:\Program Files\Microsoft sdk \Windows\v7.1\Bin\setenv. "/Release /x64 . cmd 运行:引导

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