如何在Visual Studio 2010中使用Boost

关于如何在Visual Studio中的空项目中使用Boost库的逐步说明,有什么很好的解释? html


#1楼

这是我如何使用Boost的方法: ios

  1. 下载并解压缩Boost库的zip版本。
  2. 运行bootstrap.bat文件,而后运行bjam.exe。
  3. 等待大约30分钟左右。
  4. 在Visual Studio中建立一个新项目。
  5. 转到项目->属性->连接器->常规->附加库目录,而后向其中添加boost / stage / lib目录。
  6. 转到项目->属性-> C / C ++->常规->其余包含目录,而后向其中添加boost目录。

您将可以构建您的项目而不会出现任何错误! bootstrap


#2楼

从如下网址下载加强功能: http : //www.boost.org/users/download/,例如svn windows

  • Windows->乌龟(最简单的方法)

以后:cmd->转到boost目录(“ D:\\ boostTrunk”-您在其中签出或下载并解压缩包):command: bootstrap svn

咱们在(“ D:\\ boostTrunk”)中建立了bjam.exe:以后:命令: bjam toolset = msvc-10.0 variant = debug,release threading = multi link = static (这须要一些时间〜20min。) visual-studio

以后:打开Visual Studio 2010->建立空项目->转到项目属性->设置: 网站

项目属性VS 2010

粘贴此代码,而后检查其是否有效? ui

#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;
}

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


#3楼

一个使您开始使用Visual Studio的极简示例: debug

1.今后处下载并解压Boost。

2.使用示例boost库建立一个Visual Studio空项目,该示例不须要单独编译:

#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.在Visual Studio项目属性中,设置“附加包含目录”:

项目属性

举一个很是简单的例子:

如何在Visual Studio中安装Boost库

若是您不想使用整个Boost库,请使用如下子集:

在Windows中使用Boost库的子集

若是您如今特别想了解须要编译的库:

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


#4楼

您须要Boost的哪些部分? Visual Studio随附的TR1包含不少内容,所以您能够简单地说,例如:

#include <tr1/memory>

using std::tr1::shared_ptr;

根据James的说法,这在C ++ 0x中也应该起做用:

#include <memory>

using std::shared_ptr;

#5楼

虽然说明书上的升压网站是有帮助的,这里是一个浓缩版,也是创建64库。

  • 仅当使用说明页面第3节中提到的库之一时,才须要这样作。 (例如,使用Boost.Filesystem须要编译。)若是不使用其中任何一个,只需解压缩并执行便可。

构建32位库

这会将Boost头文件安装在C:\\Boost\\include\\boost-(version) ,并将32位库安装在C:\\Boost\\lib\\i386 。 请注意,这些库的默认位置是C:\\Boost\\lib可是若是您打算为多种体系结构进行构建,则须要将它们放在i386目录下。

  1. 将Boost解压缩到新目录中。
  2. 启动一个32位MSVC命令提示符,并更改成Boost解压缩的目录。
  3. 运行: bootstrap
  4. 运行: b2 toolset=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
  5. C:\\Boost\\include\\boost-(version)到您的包含路径。

  6. C:\\Boost\\lib\\i386到您的libs路径。

构建64位库

这会将Boost头文件安装在C:\\Boost\\include\\boost-(version) ,并将64位库安装在C:\\Boost\\lib\\x64 。 请注意,这些库的默认位置是C:\\Boost\\lib可是若是您打算为多种体系结构进行构建,则须要将它们放在x64目录下。

  1. 将Boost解压缩到新目录中。
  2. 启动一个64位MSVC命令提示符,并切换到Boost解压缩的目录。
  3. 运行: bootstrap
  4. 运行: b2 toolset=msvc-12.0 --build-type=complete --libdir=C:\\Boost\\lib\\x64 architecture=x86 address-model=64 install
    • 对于Visual Studio 2012,请使用toolset=msvc-11.0
    • 对于Visual Studio 2010,请使用toolset=msvc-10.0
  5. C:\\Boost\\include\\boost-(version)到您的包含路径。
  6. C:\\Boost\\lib\\x64到您的libs路径。
相关文章
相关标签/搜索