VS2017 配置 boost_1_70

1. 下載與安裝

1.1 安裝方法1

(1) 下載html

https://www.boost.org/python

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

當前最新版本是1.70.0c++

 

(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.exebootstrap

 

(4)生成 包含目錄和庫目錄數據結構

命令行執行:

bjam.exe install stage --toolset=msvc-14.1 architecture=x86 address-model=64 --stagedir="D:\Pros\IDE\boost_1_70_0_comp\boost_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:\Boost\boost_vc_120" link=shared runtime-link=shared threading=multi debug release  

// 若是是要獲取靜態庫:

bjam install stage --toolset=msvc-14.1 --stagedir="C:\Boost\boost_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_boost\boost_1_70_0\bin\vc141-x64" link=static runtime-link=shared runtime-link=static threading=multi debug release

搭配環境變量:

your_root_path_of_boost\boost_1_70_0
your_root_path_of_boost\boost_1_70_0\bin\vc14-x64\lib

 

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:\boost裏面已經有了一個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

 

 

三、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配置心得
相關文章
相關標籤/搜索