windows下boost庫的基本使用方法

2021-07-10 12:50:34 字數 2397 閱讀 2011

因為boost都是使用模板的技術,所以所有**都是寫在乙個.hpp標頭檔案中。這樣boost中的大部分內容是不需要編譯生成相應的鏈結庫,只需要設定下面的包含目錄(或者設定一下環境變數),在原始檔中包含相應的標頭檔案就可以使用了。少部分庫需要生成鏈結庫來使用。

下面介紹完整安裝boost庫的方法:

2、解壓檔案,在命令提示符中開啟到boost庫的根目錄下:

雙擊bootstrap.bat檔案,生成bjam.exe,執行以下命令:

bjam --toolset=msvc --build-type=complete stage

或者直接雙擊bjam.exe.

等待程式編譯完成,大約要兩個小時左右,會在boost根目錄下生成bin.v2和stage兩個資料夾,其中bin.v2下是生成的中間檔案,大小在2.7g左右,可以直接刪除。stage下才是生成的dll和lib檔案。

3、開啟vs:

檢視->屬性管理器->當前專案->debug|win32->microsoft.cpp.win32.user雙擊

在彈出的屬性對話方塊中:

通用屬性->vc++目錄:"包含目錄": boost的根目錄,例: d:\visual stdio 2013\lipeng\boost\boost_1_58_0

"庫目錄": stage下的鏈結庫目錄,例:d:\visual stdio 2013\lipeng\boost\boost_1_58_0\stage\lib

通用屬性->鏈結器->常規:"附加庫目錄":同上面的"庫目錄",例:d:\visual stdio 2013\lipeng\boost\boost_1_58_0\stage\lib

至此環境就配置好了,下面測試一下:

[cpp]view plain

copy

"font-size:14px;"

>

"code"

class

="cpp"

>"font-family:courier new;"

>#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

#include 

using

namespace

boost;  

intmain()  

boost::gregorian::date dt(2009, 12, 8); //date_time 庫

assert(dt.year() == 2009);  

assert(dt.day() == 8);  

boost::gregorian::date::ymd_type ymd = dt.year_month_day();  

std::cout<

<

std::cout <

std::cout <

std::cout <

//對陣列排序操作

std::vector

> test_vc(100);  

std::vector

>::iterator beg_it = test_vc.begin();  

std::vector

>::iterator end_it = test_vc.end();  

std::srand(std::time(null));  

std::for_each(beg_it, end_it, (int

& n));  

std::copy(beg_it, end_it, std::ostream_iterator

>(std::cout, 

" "));  

std::cout <

std::sort(beg_it, end_it, std::greater

>());  

std::copy(beg_it, end_it, std::ostream_iterator

>(std::cout, 

" "));  

std::cout <

boost::posix_time::ptime pt(boost::gregorian::date(2005, 2, 6));  

std::cout <

<

//程式執行時間

system("pause"

);  

return

0;  }  

程式正確執行:

windows下!boost庫的編譯選項

解壓縮,雙擊bootstrap.bat,會生成b2.exe。用visual studio tools下的vs20xx 開發人員命令提示輸入下面你需要的命令。編譯快慢視電腦的執行速度決定,差不多半小時左右。debug b2 install prefix e boost msvc 12.0 comple...

windows下boost庫的基本使用方法

因為boost都是使用模板的技術,所以所有 都是寫在乙個.hpp標頭檔案中。這樣boost中的大部分內容是不需要編譯生成相應的鏈結庫,只需要設定下面的包含目錄 或者設定一下環境變數 在原始檔中包含相應的標頭檔案就可以使用了。少部分庫需要生成鏈結庫來使用。下面介紹完整安裝boost庫的方法 2 解壓檔...

windows下編譯和安裝boost庫

編譯位boost庫 可能boost版本太高編譯錯誤,後來我就選用boost 1 57 0.zip 解壓檔案boost 1 57 0 編譯和位環境不同,x64環境下編譯得先從開始選單啟動visual studio 的visual studio 2008 x64 win64 command prompt...