VS2017编译boost库

1.http://www.boost.org/     下载boost库。

2.解压到 D:ProgramFilesoost

3.环境配变量配置

    VS2017更加注重跨平台性,安装文件较多,VC有三个版本,分别是arm、Hostx64、Hostx86,我们使用Hostx64。
    注意,需要使用cl.exe. 默认安装时,编译器cl.exe并不在环境变量中,需要配置。
 
    测试环境变量:
    运行输入cmd,输入cl,若显示:'cl' 不是内部或外部命令,说明没有环境变量。
 
    配置环境变量:
    选择Path编辑-添加cl的路径:
     D:Program Files (x86)Microsoft Visual Studio2017EnterpriseVCToolsMSVC14.11.25503inHostx64x64
 
4.开始编译
    以管理员身份运行VS2017开发人员命令提示,英文名称x64 Native Tools Command Prompt for VS 2017
    进入目录
    cd D:ProgramFilesoostoost_1_65_1
    运行bootstrap.bat,生成b2.exe,bjam.exe和project-config.jam。
 
    很多资料说要编辑project-config.jam文件,如下
     import option ;  
     using msvc :14.1:"D:/Program Files (x86)/Microsoft Visual      Studio/2017/Enterprise/VC/Tools/MSVC/14.11.25503/bin/Hostx64/x64/cl.exe";  
    option.set keep-going : false ;
 
    编译没有成功。
 
    不修改此文件,保持不变,编译成功。
 
5.生成
      b2.exe install --toolset=msvc-14.1 --prefix="D:/ProgramFiles/boost/lib" --without-python threading=multi --build-   type=complete  address-model=64
 
     具体介绍: 

--toolset:设置编译器,如果用VC,设msvc, 用MinGW就设gcc。 

stage:可选install,选stage只生成库(静态库和动态库),install还包含include目录,其实,可以直接用我们下载下来的BOOST包里的boost目录,这个目录和install生成的include目录内容基本一样。 

--build-dir=”[temporary folder name”:编译的临时文件存放位置。 

--stagedir=” stage folder name]”:存放编译后库文件的路径,默认是stage。 

--build-type=complete:编译所有版本 

{

 

  variant=debug|release        决定编译什么版本(Debug or Release?)

 

  link=static|shared           决定使用静态库还是动态库。

 

  threading=single|multi       决定使用单线程还是多线程库。

 

  runtime-link=static|shared   决定是静态还是动态链接C/C++标准库。

 

}

 

link:是动态库还是静态库,static | shared,一般默认静态。

address-mode:address-model=64,如果没有这个属性的话,会默认生成32位的平台库,加入这个选项才能生成64位的DLL。如果运行在VS32位的命令行下需要添加” architecture=x86”,由于我们使用x64 Native Tools Command Prompt for VS 2017没有x86与x64之间的矛盾,所以未设置。 
这个过程大致需要半个小时:生成的这个文件夹就是库文件和动态链接所在。中间文件build可以直接删除。
 
 
6.测试库
 
 新建一个ConsoleApplication程序,配置boost库使用。在Project->Properties
 1.C/C++ -> General -> Additional Include Directories添加库头文件目录。
   D:ProgramFilesoostlibincludeoost-1_65_1
 2.Linker->Additional Library Directories 添加库lib文件目录。
   D:ProgramFilesoostliblib 
 
#include "stdafx.h"
#include <iostream>
#include<boost/date_time/gregorian/greg_date.hpp>

using namespace std;
int main()
{
    using boost::gregorian::date;
    date a{ 2018, 1, 1 }, b{ 2018, 1, 9 };
    std::cout << (b - a).days() << "
";

    cin.get();
    return 0;
}

运行结果为:8

 
原文地址:https://www.cnblogs.com/ike_li/p/7890868.html