如何在Visual Studio 2010中使用Boost

關於如何在Visual Studio中的空項目中使用Boost庫的逐步說明,有什麼很好的解釋? html


#1樓

這是我如何使用Boost的方法: ios

  1. 下載並解壓縮Boost庫的zip版本。
  2. 運行bootstrap.bat文件,而後運行bjam.exe。
  3. 等待大約30分鐘左右。
  4. 在Visual Studio中建立一個新項目。
  5. 轉到項目->屬性->連接器->常規->附加庫目錄,而後向其中添加boost / stage / lib目錄。
  6. 轉到項目->屬性-> C / C ++->常規->其餘包含目錄,而後向其中添加boost目錄。

您將可以構建您的項目而不會出現任何錯誤! bootstrap


#2樓

從如下網址下載加強功能: http : //www.boost.org/users/download/,例如svn windows

  • 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->建立空項目->轉到項目屬性->設置: 網站

項目屬性VS 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


#3樓

一個使您開始使用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項目屬性中,設置「附加包含目錄」:

項目屬性

舉一個很是簡單的例子:

如何在Visual Studio中安裝Boost庫

若是您不想使用整個Boost庫,請使用如下子集:

在Windows中使用Boost庫的子集

若是您如今特別想了解須要編譯的庫:

如何在Windows中使用Boost編譯的庫


#4樓

您須要Boost的哪些部分? Visual Studio隨附的TR1包含不少內容,所以您能夠簡單地說,例如:

#include <tr1/memory>

using std::tr1::shared_ptr;

根據James的說法,這在C ++ 0x中也應該起做用:

#include <memory>

using std::shared_ptr;

#5樓

雖然說明書上的升壓網站是有幫助的,這裏是一個濃縮版,也是創建64庫。

  • 僅當使用說明頁面第3節中提到的庫之一時,才須要這樣作。 (例如,使用Boost.Filesystem須要編譯。)若是不使用其中任何一個,只需解壓縮並執行便可。

構建32位庫

這會將Boost頭文件安裝在C:\\Boost\\include\\boost-(version) ,並將32位庫安裝在C:\\Boost\\lib\\i386 。 請注意,這些庫的默認位置是C:\\Boost\\lib可是若是您打算爲多種體系結構進行構建,則須要將它們放在i386目錄下。

  1. 將Boost解壓縮到新目錄中。
  2. 啓動一個32位MSVC命令提示符,並更改成Boost解壓縮的目錄。
  3. 運行: bootstrap
  4. 運行: b2 toolset=msvc-12.0 --build-type=complete --libdir=C:\\Boost\\lib\\i386 install

    • 對於Visual Studio 2012,請使用toolset=msvc-11.0
    • 對於Visual Studio 2010,請使用toolset=msvc-10.0
    • 對於Visual Studio 2017,請使用toolset=msvc-14.1
  5. C:\\Boost\\include\\boost-(version)到您的包含路徑。

  6. C:\\Boost\\lib\\i386到您的libs路徑。

構建64位庫

這會將Boost頭文件安裝在C:\\Boost\\include\\boost-(version) ,並將64位庫安裝在C:\\Boost\\lib\\x64 。 請注意,這些庫的默認位置是C:\\Boost\\lib可是若是您打算爲多種體系結構進行構建,則須要將它們放在x64目錄下。

  1. 將Boost解壓縮到新目錄中。
  2. 啓動一個64位MSVC命令提示符,並切換到Boost解壓縮的目錄。
  3. 運行: bootstrap
  4. 運行: b2 toolset=msvc-12.0 --build-type=complete --libdir=C:\\Boost\\lib\\x64 architecture=x86 address-model=64 install
    • 對於Visual Studio 2012,請使用toolset=msvc-11.0
    • 對於Visual Studio 2010,請使用toolset=msvc-10.0
  5. C:\\Boost\\include\\boost-(version)到您的包含路徑。
  6. C:\\Boost\\lib\\x64到您的libs路徑。
相關文章
相關標籤/搜索