無法開啟檔案“libboost_thread-vc141-mt-gd-1_69.lib“的解決辦法
Visual Studio 2017 配置Boost庫,如何編譯和選擇,遇到無法開啟檔案“libboost_thread-vc141-mt-gd-1_69.lib“的解決辦法...
1,到官網下載boost,www.boost.org 這裡我下載的1-69版本.
2,安裝,解壓後執行bootstrap.bat檔案。稍等一小會就OK。
3,編譯boost庫。注意一定要使用VS2017的x86本機工具命令提示,這個可以在VS2017的安裝選單裡面找到。進入命令列提示,輸入下面的內容:
bjam -j4 --debug-symbols=on --build-type=complete toolset=msvc-14.1 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_69_0\boost_1_69_0 The following directory should be added to linker library paths: E:\boost_1_69_0\boost_1_69_0\stage\lib
4,在VS2017中配置boost環境
專案屬性 > 配置屬性,然後看到下面的選擇項:
常規 > 平臺工具集,選擇 Visual Studio 2017 (v141).
下面的兩個操作,需要你將上面boost編譯的時候告訴你的目錄替換到下面說的有關目錄資訊裡面去。
看到 "C\C++" 常規 > 附加包含目錄,增加"E:\boost_1_69_0\boost_1_69_0"
最後,看到“連結器”常規 > 附加庫目錄,增加"E:\boost_1_69_0\boost_1_69_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學習的一些文章,值得參考。