關於如何在Visual Studio中的空項目中使用Boost庫的逐步說明,有什麼很好的解釋? html
這是我如何使用Boost的方法: ios
您將可以構建您的項目而不會出現任何錯誤! bootstrap
從如下網址下載加強功能: http : //www.boost.org/users/download/,例如svn windows
以後:cmd->轉到boost目錄(「 D:\\ boostTrunk」-您在其中籤出或下載並解壓縮包):command: bootstrap svn
咱們在(「 D:\\ boostTrunk」)中建立了bjam.exe:以後:命令: bjam toolset = msvc-10.0 variant = debug,release threading = multi link = static (這須要一些時間〜20min。) visual-studio
以後:打開Visual Studio 2010->建立空項目->轉到項目屬性->設置: 網站
粘貼此代碼,而後檢查其是否有效? ui
#include <iostream> #include <boost/shared_ptr.hpp> #include <boost/regex.hpp> using namespace std; struct Hello { Hello(){ cout << "Hello constructor" << endl; } ~Hello(){ cout << "Hello destructor" << endl; cin.get(); } }; int main(int argc, char**argv) { //Boost regex, compiled library boost::regex regex("^(Hello|Bye) Boost$"); boost::cmatch helloMatches; boost::regex_search("Hello Boost", helloMatches, regex); cout << "The word between () is: " << helloMatches[1] << endl; //Boost shared pointer, header only library boost::shared_ptr<Hello> sharedHello(new Hello); return 0; }
資源: https : //www.youtube.com/watch?v=5AmwIwedTCM spa
一個使您開始使用Visual Studio的極簡示例: debug
1.今後處下載並解壓Boost。
2.使用示例boost庫建立一個Visual Studio空項目,該示例不須要單獨編譯:
#include <iostream> #include <boost/format.hpp> using namespace std; using namespace boost; int main() { unsigned int arr[5] = { 0x05, 0x04, 0xAA, 0x0F, 0x0D }; cout << format("%02X-%02X-%02X-%02X-%02X") % arr[0] % arr[1] % arr[2] % arr[3] % arr[4] << endl; }
3.在Visual Studio項目屬性中,設置「附加包含目錄」:
舉一個很是簡單的例子:
若是您不想使用整個Boost庫,請使用如下子集:
若是您如今特別想了解須要編譯的庫:
您須要Boost的哪些部分? Visual Studio隨附的TR1包含不少內容,所以您能夠簡單地說,例如:
#include <tr1/memory> using std::tr1::shared_ptr;
根據James的說法,這在C ++ 0x中也應該起做用:
#include <memory> using std::shared_ptr;
雖然說明書上的升壓網站是有幫助的,這裏是一個濃縮版,也是創建64庫。
這會將Boost頭文件安裝在C:\\Boost\\include\\boost-(version)
,並將32位庫安裝在C:\\Boost\\lib\\i386
。 請注意,這些庫的默認位置是C:\\Boost\\lib
可是若是您打算爲多種體系結構進行構建,則須要將它們放在i386
目錄下。
bootstrap
運行: b2 toolset=msvc-12.0 --build-type=complete --libdir=C:\\Boost\\lib\\i386 install
toolset=msvc-11.0
toolset=msvc-10.0
toolset=msvc-14.1
將C:\\Boost\\include\\boost-(version)
到您的包含路徑。
C:\\Boost\\lib\\i386
到您的libs路徑。 這會將Boost頭文件安裝在C:\\Boost\\include\\boost-(version)
,並將64位庫安裝在C:\\Boost\\lib\\x64
。 請注意,這些庫的默認位置是C:\\Boost\\lib
可是若是您打算爲多種體系結構進行構建,則須要將它們放在x64
目錄下。
bootstrap
b2 toolset=msvc-12.0 --build-type=complete --libdir=C:\\Boost\\lib\\x64 architecture=x86 address-model=64 install
toolset=msvc-11.0
toolset=msvc-10.0
C:\\Boost\\include\\boost-(version)
到您的包含路徑。 C:\\Boost\\lib\\x64
到您的libs路徑。