Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在VisualStudio2010中使用Boost_C++_Visual Studio 2010_Boost - Fatal编程技术网

C++ 如何在VisualStudio2010中使用Boost

C++ 如何在VisualStudio2010中使用Boost,c++,visual-studio-2010,boost,C++,Visual Studio 2010,Boost,关于如何在VisualStudio中的空项目中使用Boost库,有什么好的逐步解释吗?您需要Boost的哪些部分?很多东西都是VisualStudio附带的TR1的一部分,因此您可以简单地说,例如: #include <tr1/memory> using std::tr1::shared_ptr; #包括 使用std::tr1::shared\u ptr; 根据James的说法,这也应该有效(在C++0x中): #包括 使用std::shared_ptr; 虽然Boost网站上

关于如何在VisualStudio中的空项目中使用Boost库,有什么好的逐步解释吗?

您需要Boost的哪些部分?很多东西都是VisualStudio附带的TR1的一部分,因此您可以简单地说,例如:

#include <tr1/memory>

using std::tr1::shared_ptr;
#包括
使用std::tr1::shared\u ptr;
根据James的说法,这也应该有效(在C++0x中):

#包括
使用std::shared_ptr;
虽然Boost网站上的有帮助,但这里有一个精简版,它也可以构建x64库

  • 只有在使用“说明”页的中提到的某个库时,才需要执行此操作。(例如,要使用Boost.Filesystem需要编译。)如果您没有使用任何一个,只需解压缩即可
构建32位库 这将在
C:\Boost\include\Boost-(version)
下安装Boost头文件,并在
C:\Boost\lib\i386
下安装32位库。请注意,库的默认位置是
C:\Boost\lib
,但如果您计划为多个体系结构构建,则需要将它们放在
i386
目录下

  • 将Boost解压到一个新目录中
  • 启动一个32位MSVC命令提示符,并切换到解压缩Boost的目录
  • 运行:
    bootstrap
  • 运行:
    b2工具集=msvc-12.0--build type=complete--libdir=C:\Boost\lib\i386 install

    • 对于Visual Studio 2012,请使用
      toolset=msvc-11.0
    • 对于Visual Studio 2010,请使用
      toolset=msvc-10.0
    • 对于Visual Studio 2017,请使用
      toolset=msvc-14.1
  • C:\Boost\include\Boost-(version)
    添加到包含路径

  • C:\Boost\lib\i386
    添加到您的libs路径
  • 构建64位库 这将在
    C:\Boost\include\Boost-(version)
    下安装Boost头文件,并在
    C:\Boost\lib\x64
    下安装64位库。请注意,库的默认位置是
    C:\Boost\lib
    ,但如果您计划为多个体系结构构建,则需要将它们放在
    x64
    目录下

  • 将Boost解压到一个新目录中
  • 启动64位MSVC命令提示符,并切换到解压缩Boost的目录
  • 运行:
    bootstrap
  • 运行:
    b2工具集=msvc-12.0--构建类型=完成--libdir=C:\Boost\lib\x64架构=x86地址模型=64安装
    • 对于Visual Studio 2012,请使用
      toolset=msvc-11.0
    • 对于Visual Studio 2010,请使用
      toolset=msvc-10.0
  • C:\Boost\include\Boost-(version)
    添加到包含路径
  • C:\Boost\lib\x64
    添加到您的libs路径
  • 虽然已经相当不错了,但我将根据要求对VisualStudio2010进行更具体的扩展,并包括在需要外部库的各种可选组件中编译的信息

    如果您使用的是仅标题库,那么您所需要做的就是取消boost下载的归档并设置环境变量。下面的说明仅为Visual Studio设置环境变量,而不是整个系统。注意你只需要做一次

  • 将最新版本的boost(编写时为1.47.0)解压缩到您选择的目录中(例如
    C:\boost\u 1\u 47\u 0
  • 在Visual Studio中创建新的空项目
  • 打开属性管理器并展开所选平台的一个配置
  • 选择并右键单击
    Microsoft.Cpp..user
    ,然后选择
    Properties
    打开属性页进行编辑
  • 选择左侧的
    VC++目录
  • 编辑
    包含目录
    部分以包含boost源文件的路径
  • 如果需要,为您选择的不同平台重复步骤3-6
  • 如果您想使用boost中需要构建的部分,但没有需要外部依赖关系的功能,那么构建它是相当简单的

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

    • Win32:
      b2——工具集=msvc-10.0——构建类型=完成阶段
    • x64:
      b2--toolset=msvc-10.0--build type=complete architecture=x86 address model=64 stage
  • 去散步/看电影或

  • 从上面的指令集中执行步骤2-6,以设置环境变量
  • 编辑
    库目录
    部分以包括boost库输出的路径。(以上示例和说明的默认值为
    C:\boost\u 1\u 47\u 0\stage\lib
    。如果希望x86和x64并排(例如to
    \lib\x86
    &
    \lib\x64
    ),请先重命名并移动目录)
  • 如果需要,为您选择的不同平台重复步骤2-6
  • 如果您需要可选组件,那么您还有更多的工作要做。这些是:

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

  • 将最新版本的bzip2库(写入时为1.0.6)源文件解压缩到您选择的目录中(例如
    C:\bzip2-1.0.6
  • 按照上面的第二组说明构建boost,但在步骤5中运行b2时添加选项
    -sBZIP2_SOURCE=“C:\bzip2-1.0.6”
  • Boost.IOStreams Zlib滤波器
    #include <memory>
    
    using std::shared_ptr;
    
    <?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>
    
    #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;
    }
    
    #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;  
    }  
    
    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
    
    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
    
    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
    
    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)