Mac安裝boost

boost安裝

1.boost安裝包下載
https://sourceforge.net/projects/boost/files/boost/1.62.0/

2.解壓并進(jìn)入boost_1_62_0文件夾

3.執(zhí)行boostrap.sh

./boostrap.sh

4.上一步執(zhí)行成功后會(huì)生成b2腳本,執(zhí)行它

./b2

執(zhí)行完畢后,頭文件在boost_1_62_0/boost文件夾下
庫文件在boost_1_62_0/stage/lib文件夾下
或者執(zhí)行

./b2 install 

執(zhí)行完畢后頭文件在/usr/local/include下
庫文件在/usr/local/lib下

到這里安裝結(jié)束

測試

直接包含一個(gè)頭文件編譯看是否通過即可

#include <boost/asio.hpp>
int main()
{
}

g++使用第三方庫編譯是如下命令

g++ a.cpp  -I 頭文件路徑 -L 庫文件路徑 -l 動(dòng)態(tài)鏈接庫

對(duì)應(yīng)到我們這里應(yīng)該是

 g++ a.cpp  -I /usr/local/include -L /usr/local/lib -l boost_system -l boost_thread

必須要加,-l boost_system -l boost_thread,否則會(huì)報(bào)錯(cuò)

  Undefined symbols for architecture x86_64:
“boost::system::system_category()”, referenced from: 
boost::asio::error::get_system_category() in a-0e6774.o 
___cxx_global_var_init.2 in a-0e6774.o 
“boost::system::generic_category()”, referenced from: 
___cxx_global_var_init in a-0e6774.o 
___cxx_global_var_init.1 in a-0e6774.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation)

XCode上使用

1.點(diǎn)擊【項(xiàng)目工程文件】-》【Targets】-》【BuildSetting】-》【Search Paths】-》【Header Search Paths】輸入頭文件路徑
2.點(diǎn)擊【項(xiàng)目工程文件】-》【Targets】-》【BuildSetting】-》【Search Paths】-》【Library Search Paths】輸入庫文件路徑
3.點(diǎn)擊【項(xiàng)目工程文件】-》【Targets】-》【BuildSetting】-》【Linking】-》【Other Linker Flags】輸入鏈接選項(xiàng),輸入-l boost_system -l boost_thread

大功告成!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容