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


当前回答

您还可以尝试-j%NUMBER_OF_PROCESSORS%作为参数,它将使用所有的内核。让我的四核速度超快。

其他回答

下载促进: http://www.boost.org/users/download/ 例如:SVN

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

之后: cmd ->进入boost目录(“D:\boostTrunk”-在那里您签出或下载并提取包): 命令: 引导

我们创建了bjam.exe在("D:\boostTrunk") 之后: 命令: Bjam toolset=msvc-10.0 variant=debug,release threading=multi link=static (大概需要20分钟左右)

后: 打开Visual studio 2010 ->创建空项目->到项目属性->设置:

粘贴此代码并检查它是否工作?

#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

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

1.从这里下载并解压Boost。

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

举个简单的例子:

如何在Visual Studio中安装Boost库

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

使用Windows中的boost库的子集

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

如何在Windows中使用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).

好运!

还有一个小提示:如果你想减少编译时间,你可以添加标志

j2

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

您还可以尝试-j%NUMBER_OF_PROCESSORS%作为参数,它将使用所有的内核。让我的四核速度超快。