VS2017編譯boost庫


1.http://www.boost.org/     下載boost庫。

2.解壓到 D:\ProgramFiles\boost

3.環境配變量配置

    VS2017更加注重跨平台性,安裝文件較多,VC有三個版本,分別是arm、Hostx64、Hostx86,我們使用Hostx64。
    注意,需要使用cl.exe. 默認安裝時,編譯器cl.exe並不在環境變量中,需要配置。
 
    測試環境變量:
    運行輸入cmd,輸入cl,若顯示:'cl' 不是內部或外部命令,說明沒有環境變量。
 
    配置環境變量:
    選擇Path編輯-添加cl的路徑:
     D:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\bin\Hostx64\x64
 
4.開始編譯
    以管理員身份運行VS2017開發人員命令提示,英文名稱x64 Native Tools Command Prompt for VS 2017
    進入目錄
    cd D:\ProgramFiles\boost\boost_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:\ProgramFiles\boost\lib\include\boost-1_65_1
 2.Linker->Additional Library Directories 添加庫lib文件目錄。
   D:\ProgramFiles\boost\lib\lib 
 
#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() << "\n";

    cin.get();
    return 0;
}

運行結果為:8

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM