Boost C++ 库均带有源代码。其中大多数库只包含头文件,可以直接使用,但也有一些库需要编译。 为了尽可能容易安装,可以使用 Boost Jam 进行自动安装。 无需逐个库进行检查和编译,Boost Jam 自动安装整个库集。 它支持许多操作系统和编译器,并且知道如何基于适当的配置文件来编译单个库。

一、下载Boost库

官网自行下载,注意不要下载Prebuilt版本,这里以1.7版本为例。下载完成后解压缩。

二、编译

  1. 打开VS提供的CL工具,更改目录到boost路径
  2. 执行如下命令
    .\bootstrap.bat
    .\b2.exe

三、测试Boost

  1. 打开VS2019,新建一个空C++项目,并创建main.cpp 文件。
  2. 把Boost根目录添加到附加包含目录
  3. 添加附加库目录,如下:
  4. 测试(以多线程并行排序为例)
    #include <iostream>
    #include <boost/sort/sort.hpp>
    #include <algorithm>
    #include <vector>
    using namespace std;
    int main()
    {
    	vector<int> arr;
    	while (arr.size() < 100) arr.push_back(std::rand());
    	boost::sort::block_indirect_sort(std::begin(arr), std::end(arr));
    	for_each(std::begin(arr), std::end(arr), [](int& a) {
    		cout << a << "\t";
    	});
    	return 0;
    }
  5. 参考链接:https://www.boost.org/doc/libs/1_70_0/more/getting_started/windows.html

四、后记

很久以前就想试试Boost了,一直没有时间,也没时间写博客,今天终于有时间试试了,还不错,另外附上一个比较好的在线编码的平台:https://studio.dev.tencent.com/

 

分类: 编程