1,到官網下載最新的boost,www.boost.org 這里我下載的1-63版本.
2,安裝,解壓后運行bootstrap.bat文件。稍等一小會就OK。
3,編譯boost庫。注意一定要使用VS2015的x86本機工具命令提示,這個可以在VS2015的安裝菜單里面找到。進入命令行提示,輸入下面的內容:
bjam -j4 --debug-symbols=on --build-type=complete toolset=msvc-14.0 threading=multi runtime-link=shared address-model=32
注意這里指定的運行庫類型是動態鏈接庫:
runtime-link=shared
當然也可以選擇靜態庫,這樣指定即可:
runtime-link=static
根據電腦配置,太低可能要30分鍾到一小時。然后等待編譯完畢。
編譯完后,屏幕會有下面的提示:
...updated 2376 targets... The Boost C++ Libraries were successfully built! The following directory should be added to compiler include paths: E:\boost_1_63_0\boost_1_63_0 The following directory should be added to linker library paths: E:\boost_1_63_0\boost_1_63_0\stage\lib
4,在VS2015中配置boost環境
項目屬性 > 配置屬性,然后看到下面的選擇項:
常規 > 平台工具集,選擇 Visual Studio 2015 (v140).
下面的兩個操作,需要你將上面boost編譯的時候告訴你的目錄替換到下面說的有關目錄信息里面去。
看到 "C\C++" 常規 > 附加包含目錄,增加"E:\boost_1_63_0\boost_1_63_0"
最后,看到“鏈接器”常規 > 附加庫目錄,增加"E:\boost_1_63_0\boost_1_63_0\stage\lib"
注意:一定要進行這樣正確的設置,否則編譯使用boost的程序總是會提示有問題。
5,使用boost:
#include "stdafx.h" #include <iostream> #include <boost/thread/thread.hpp> void hello() { std::cout << "Hello world, I'm a thread!" << std::endl; } int main() { boost::thread thrd(&hello); thrd.join(); }
出錯:
錯誤 LNK1104 無法打開文件“libboost_thread-vc140-mt-gd-1_63.lib”
解決辦法:
因為上面選擇的是以動態鏈接庫的形式編譯的boost庫,所以這里要選擇 多線程調試 DLL(/MDd)。
再去運行一下。就OK了。
6,參考資料
新人,第一次使用C++,現在使用C++的人很少了,問了一圈都沒有人會這個問題,查找了很多資料,這里貼出有用的參考資料:
http://blog.csdn.net/zhaoya_huangqing/article/details/47318479
標題跟我差不多,多謝這位博主了。
http://www.cnblogs.com/rok-aya/p/4986261.html
轉帖的老外的文章,很有啟發性,跟本文的問題對路。
https://msdn.microsoft.com/zh-cn/vstudio/669zx6zc.aspx
MSDN官方的指導如何實現項目屬性,進階
http://www.cnblogs.com/mr-wid/archive/2013/01/22/2871105.html
http://www.cnblogs.com/wendao/archive/2011/11/28/article2_boost_bind.html
boost學習的一些文章,值得參考。