zoukankan      html  css  js  c++  java
  • VS2017 配置 boost_1_70

    1. 下载与安装

    1.1 安装方法1

    (1) 下载

    https://www.boost.org/

    或者使用 https://sourceforge.net/projects/boost/files/boost-binaries/

    当前最新版本是1.70.0

    (2)配置

    下载好后,解压到自己的IDE库目录中,找到其中的bootstrap.bat文件

     

    选择vs2017 —> visual studio tools —> vc —> x86_x64 Cross Tools Command Prompt for VS 2,打开命令行:

     

    切换到boost_1_70_0的安装目录。执行那个.bat文件

    (3)执行后,将会在boost当前目录下增加了几个文件,找到其中的bjam.exe

    (4)生成 包含目录和库目录

    命令行执行:

    bjam.exe install stage --toolset=msvc-14.1 architecture=x86 address-model=64 --stagedir="D:ProsIDEoost_1_70_0_compoost_lib64-msvc-14.1" link=static runtime-link=shared runtime-link=static --build-type=complete --with-system --with-thread --with-date_time --with-filesystem --with-serialization threading=multi debug release
    

    b2的更多使用方式,输入 b2 --help 便可查看。

    注意,执行的命令“--with-system --with-thread --with-date_time --with-filesystem --with-serialization”,会仅生成这几个库,如boot_iostreams等库就不会生成。

    没有with的话,就默认全部输出。

    Note:

    1) 有关b2的参数

    // 如果要获取动态库:

    bjam install stage --toolset=msvc-14.1 --stagedir="C:Boostoost_vc_120" link=shared runtime-link=shared threading=multi debug release  

    // 如果是要获取静态库:

    bjam install stage --toolset=msvc-14.1 --stagedir="C:Boostoost_vc_120" link=static runtime-link=static threading=multi debug release  

     其中,注意修改--toolset=msvc-14.1,将14.1修改成对应的vs版本号,14.1是VS2017的版本号。

    目标地址也要修改成你所需的。

    或参考, 增加如下参数

    --without-graph --without-graph_parallel

    注意,不要漏了install,它会帮你把头文件集合到一个文件夹中。

    MSVC 版本号对应:

    打开Visual Studio Installer,选择相应的工具集进行安装。

    1. MSVC++ 14.1 _MSC_VER == ??00 (Visual Studio 2017)
    2. MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
    3. MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013)
    4. MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012)
    5. MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010)
    6. MSVC++ 9.0  _MSC_VER == 1500 (Visual Studio 2008)
    7. MSVC++ 8.0  _MSC_VER == 1400 (Visual Studio 2005)
    8. MSVC++ 7.1  _MSC_VER == 1310 (Visual Studio 2003)
    9. MSVC++ 7.0  _MSC_VER == 1300
    10. MSVC++ 6.0  _MSC_VER == 1200
    11. MSVC++ 5.0  _MSC_VER == 1100

    vs2017 可以支持boost c++ library 针对msvc-14.1的编译选项。

    等待5-10min即可完成。

    2)直接用运行b2.exe

    可以在文件夹中找到它,然后双击。后面就是漫长的编译过程啦,至少需要二十来分钟。

    最后两个路径会在使用Boost库时工程属性中包含目录库目录中用到。

     

     这时boost库已经安装、编译成功。

     1.2 安装方法2 (博主推荐)

    或者使用下面的方式进行操作:

    也可以换下载路径:https://dl.bintray.com/boostorg/release/1.70.0/binaries/ 去下载。

     此时使用命令:

    bjam stage --toolset=msvc-14.1 architecture=x86 address-model=64 --without-graph --without-graph_parallel 
    --stagedir="your_root_path_of_boostoost_1_70_0invc141-x64" link=static runtime-link=shared runtime-link=static threading=multi debug release

    搭配环境变量:

    your_root_path_of_boostoost_1_70_0
    your_root_path_of_boostoost_1_70_0invc14-x64lib

    1.3 出现问题

    如果在类似VS调用时,出现错误    LNK1104    无法打开文件“libboost_thread-vc141-mt-gd-x64-1_69.lib”   

    下面是结局的步骤。先说一下报错的原因,这个文件名是libboost_thread-vc141-mt-gd-1_69.lib,

    第一个表示的是vc141表示使用的是vc141进行编辑的,也就是vc2017,如果是vs2015就应该出来vc140;

    第二个mt表示的是使用threading=muti多线程编译出来的。

    第三个gd表示的是debug版本,与其对应的是release版本。

    第四个x64表示的是64位系统,如果是x86表示的就是32位系统,还有1_69表示的就是boost版本是1_69_0.,如果是1_70表示的就是boost1_70_0。所以这个地方注意两点,1就是你下载的boost版本要对应,2就是使用vs编译的版本要对应。

    使用 1.2 方法下载boost。使用VS开发人员命令提示,右键使用管理员身份打开。

    然后运行里面的bootstrap.bat文件。

    然后使用下列语句进行编译:

    bjam stage --toolset=msvc-14.1 --without-python --stagedir="c:Boost" link=static runtime-link=shared runtime-link=static threading=multi debug release 

    然后就是等待漫长的编译过程,在这个过程中,我们可以先看一下编译出来的东西是不是跟我们预期的一样的。

    可以看到写的路径c:oost里面已经有了一个lib文件夹,这里面就是我们所需要的lib

     2. 测试

    (1)新建vs2017 c++项目,并添加boost依赖库

    点击菜单栏 项目——>属性——>选择VC++目录,在包含目录 和 库目录添加以上2个路径。

     (2)代码

    #include <boost/lexical_cast.hpp>     
    #include <iostream>   
    
    using namespace std;
    using namespace boost;
    
    int main()
    {
    	//system("chcp 65001");
    
    	double a = lexical_cast<double>("3.1415926");
    	string str = lexical_cast<string>("3.1415926");
    	cout << "This is a number: " << a << endl;
    	cout << "This is a string: " << str << endl;
    	int b = 0;
    	try {
    		b = lexical_cast<int>("neo");
    	}
    	catch (bad_lexical_cast& e) {
    		cout << e.what() << endl;
    	}
    	return 0;
    }

    参考VS工程的源码: boost_test.rar

    3、boost库的说明

    c++ boost库官网

    官网最新版文档说明:https://www.boost.org/doc/libs/1_70_0/

    Boost库是一个可移植、提供源代码的C++库,作为标准库的后备,是C++标准化进程的开发引擎之一,是为C++语言标准库提供扩展的一些C++程序库的总称

    Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成为下一代C++标准库内容。在C++社区中影响甚大,是不折不扣的“准”标准库。Boost由于其对跨平台的强调,对标准C++的强调,与编写平台无关。大部分boost库功能的使用只需包括相应头文件即可,少数(如正则表达式库,文件系统库等)需要链接库。但Boost中也有很多是实验性质的东西,在实际的开发中使用需要谨慎。

    Boost库由Boost社区组织开发、维护。其目的是为C++程序员提供免费、同行审查的、可移植的程序库。Boost库可以与C++标准库完美共同工作,并且为其提供扩展功能。Boost库使用Boost License来授权使用。

    Boost社区建立的初衷之一就是为C++的标准化工作提供可供参考的实现,Boost社区的发起人Dawes本人就是C++标准委员会的成员之一。在Boost库的开发中,Boost社区也在这个方向上取得了丰硕的成果。在送审的C++标准库TR1中,有十个Boost库成为标准库的候选方案。在更新的TR2中,有更多的Boost库被加入到其中。从某种意义上来讲,Boost库成为具有实践意义的准标准库。
    可下载Boost C++ Libraries安装boost库。大部分boost库功能的使用只需包括相应头文件即可,少数(如正则表达式库,文件系统库等)需要链接库。里面有许多具有工业强度的库,如graph库。

    3.1 主要分类

    按照功能分类 的Boost库列表按照实现的功能,Boost 可为大致归入以下20个分类,在下面的分类中,有些库同时归入几种类别。

    字符串和文本处理
    a) Conversion
    b) Format
    c) IOStream
    d) Lexical Cast
    e) Regex
    f) Spirit
    g) String Algo
    h) Tokenizer
    i) Wave
    j) Xpressive
    
    容器
    a) Array
    b) Bimap
    c) Circular Buffer
    d) Disjoint Sets
    e) Dynamic Bitset
    f) GIL
    g) Graph
    h) ICL
    i) Intrusive
    j) Multi-Array
    k) Multi-Index
    l) Pointer Container
    m) Property Map
    n) Property Tree
    o) Unordered
    p) Variant
    
    迭代器
    a) GIL
    b) Graph
    c) Iterators
    d) Operators
    e) Tokenizer
    
    算法
    a) Foreach
    b) GIL
    c) Graph
    d) Min-Max
    e) Range
    f) String Algo
    g) Utility
    
    函数对象和高阶编程
    a) Bind
    b) Function
    c) Functional
    d) Functional/Factory
    e) Functional/Forward
    f) Functional/Hash
    g) Lambda
    h) Member Function
    i) Ref
    j) Result Of
    k) Signals
    l) Signals2
    m) Utility
    
    泛型编程
    a) Call Traits
    b) Concept Check
    c) Enable If
    d) Function Types
    e) GIL
    f) In Place Factory, Typed In Place Factory
    g) Operators
    h) Property Map
    i) Static Assert
    j) Type Traits
    
    模板元编程
    
    a) Function Types
    b) Fusion
    c) MPL
    d) Proto
    e) Static Assert
    f) Type Traits
    
    预处理元编程
    a) Preprocessors
    
    并发编程
    
    a) Asio
    b) Interprocess
    c) MPI
    d) Thread
    
    数学和数字
    
    a) Accumulators
    b) Integer
    c) Interval
    d) Math
    e) Math Common Factor
    f) Math Octonion
    g) Math Quaternion
    h) Math/Special Functions
    i) Math/Statistical Distributions
    j) Multi-Array
    k) Numeric Conversion
    l) Operators
    m) Random
    n) Rational
    o) uBLAS
    
    排错和测试
    
    a) Concept Check
    b) Static Assert
    c) Test
    
    数据结构
    
    a) Any
    b) Bitmap
    c) Compressed Pair
    d) Fusion
    e) ICL
    f) Multi-Index
    g) Pointer Container
    h) Property Tree
    i) Tuple
    j) Uuid
    k) Variant
    
    图像处理
    
    a) GIL
    
    输入输出
    
    a) Asio
    b) Assign
    c) Format
    d) IO State Savers
    e) IOStreams
    f) Program Options
    g) Serialization
    
    跨语言混合编程
    
    a) Python
    
    内存管理
    
    a) Pool
    b) Smart Ptr
    c) Utility
    
    解析
    a) Spirit
    
    编程接口
    a) Function
    b) Parameter
    
    杂项
    a) Compressed Pair
    b) Conversion
    c) CRC
    d) Date Time
    e) Exception
    f) Filesystem
    g) Flyweight
    h) Lexical Cast
    i) Meta State Machine
    j) Numeric Conversion
    k) Optional
    l) Polygon
    m) Program Options
    n) Scope Exit
    o) Statechart
    p) Swap
    q) System
    r) Timer
    s) Tribool
    t) Typeof
    u) Units
    v) Utility
    w) Value Initialized
    
    编译器问题的变通方案
    
    a) Compatibility
    b) Config
    
    3.2 常用库
    Regex
    正则表达式库
    Spirit
    LL parser framework,用C++代码直接表达EBNF
    Graph
    图组件和算法
    Lambda
    在调用的地方定义短小匿名的函数对象,很实用的functional功能
    concept check
    检查泛型编程中的concept
    Mpl
    用模板实现的元编程框架
    Thread
    可移植的C++多线程库
    Python
    把C++类和函数映射到Python之中
    Pool
    内存池管理
    smart_ptr
    5个智能指针,学习智能指针必读,一份不错的参考是来自CUJ的文章:
    相关图书编辑
    Boost程序库完全开发指南:深入C++“准”标准库
    C++11/14高级编程:Boost程序库探秘(第3版)
    Boost程序库探秘:深度解析C++准标准库
    View Code

    参考文章

    CUDA 9.1/9.2 与 Visual Studio 2017 (VS2017 15.6.4) 的不兼容问题

    vs2015+qt5.9+CGAL4.14配置心得
     
  • 相关阅读:
    初始Openwrt
    Angular CLI 使用教程指南参考
    Visual Studio Code怎么在同一窗口打开多个项目文件?
    mysql查看数据表是否有重复数据
    Angular UI框架 Ng-alain @delon的脚手架的生成开发模板
    VS2010 WDK7.1.0 Win7_64
    Nodejs使用TLS
    python定时执行方法
    Visual Studio Code 使用Git进行版本控制
    VSCode中设置Python解释器和pylint的波浪线问题
  • 原文地址:https://www.cnblogs.com/arxive/p/11204508.html
Copyright © 2011-2022 走看看