Linux系統下安裝c++ boost開源庫教程
阿新 • • 發佈:2020-12-17
技術標籤:c++
=>>>安裝Boost
1、下載原始碼:
進入網址:http://www.boost.org/users/download/
在官網上可以下載原始碼包,目前官網上最新的軟體包是boost_1_75_0 版本。針對Linux平臺,本人下載的是boost_1_75_0.tar.bz2 檔案。
- 解壓壓縮包
tar -xvf boost_1_75_0.tar.bz2
- 安裝boost庫
執行解壓後生成的bootstrap.sh檔案:
cd ./boost_1_75_0
./bootstrap.sh
然後使用b2工具進行安裝:
sudo ./b2 install
安裝完畢之後,標頭檔案預設在/usr/local/include目錄中,.a與.so檔案在/usr/local/lib目錄下
- 測試
新建asio_server.cpp 檔案,程式碼如下
#include<iostream>
#include<boost/asio.hpp>
#include<boost/date_time/posix_time/posix_time.hpp>
int main()
{
boost::asio::io_service io;
boost::asio::deadline_timer t(io,boost::posix_time::seconds(5));
t.wait();
std::cout<<"hello,world" <<std::endl;
return 0;
}
編譯:
g++ asio_server.cpp -lboost_system -lpthread -o asio_server
輸出:
===================================
附錄:Boost C++ 庫的詳細介紹
詳細介紹使用可以參見:http://zh.highscore.de/cpp/boost/