2016年9月23日 星期五

visual studio 環境架設 boost c++ libraries

作業系統 : windows 7 sp1 x64

編譯程式 : visual C++ 12.0 (使用 visual studio 2013)

1.首先到boost的官網下載最新的lib,並解壓縮到C:\Boost Library\
 http://www.boost.org/users/download/
筆者使用的版本是 boost_1_61_0

2.然後前往這個位址
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts
使用系統管理員權限執行
VS2013 x64 Cross Tools 命令提示字元

3.執行指令
bootstrap
生成b2.exe後
b2.exe -j8 address-model=64 link=static threading=multi toolset=msvc-12.0 variant=release stage

-j8用8核心
address-model=64 在64位元指定
link=static在./static的資料夾下編譯lib檔多核心運算
threading=multi多核心運算
toolset=msvc-12.0 Visual C++ 12板,可參考https://en.wikipedia.org/wiki/Visual_C%2B%2B
這個步驟會花比較多一點的時間 大概30分鐘左右

4.然後我們建立一個專案輸入程式
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

int main()
{
using namespace boost::lambda;
typedef std::istream_iterator<int> in;

std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " ");
}

5.對著專案名稱按滑鼠右鍵

左邊點選VC++ Directories 
include Directories 的地方輸入C:\Boost Library\boost_1_61_0
Library Directories 則輸入 C:\Boost Library\boost_1_61_0\stage\lib
PS : 不能直接鍵入 要用資料夾的方式瀏覽路徑
完成後如上圖所示

6.
左邊點選Linker
Additional Library Directoris的地方輸入 C:\Boost Library\boost_1_61_0\stage\lib

7.


左邊選擇Precompiled Headers
Percompiled Hearder的地方選擇Not Using Precompiled Headers

8.執行並編譯程式 成功







參考
http://www.boost.org/doc/libs/1_60_0/doc/html/bbv2/reference.html
http://www.boost.org/doc/libs/1_60_0/more/getting_started/windows.html
https://www.ptt.cc/bbs/Windows/M.1242287062.A.27C.html
https://msdn.microsoft.com/en-us/library/8f8h5cxt.aspx
https://www.ptt.cc/bbs/C_and_CPP/M.1455637005.A.3C0.html
http://littlej1990.blogspot.tw/2015/05/boost-c-library.html

沒有留言:

張貼留言