boost庫安裝和使用


1. 下載最新的boost庫:http://www.boost.org/
本文使用的是boost_1_66_0.tar.gz,

2. Boost庫安裝步驟:

> 解壓下載文件,例如下載文件在~/Downloads下
$ cd ~/Downloads
$ tar -xzvf boost_1_66_0.tar.gz

$ cd boost_1_66_0
$ ./bootstrap.sh //准備工作


$ ./b2 //編譯,該過程時間比較長

$ sudo ./b2 install //安裝boost庫
//將生成的庫安裝到/usr/local/lib目錄下面,
//頭文件放在/usr/local/include/目錄下面


測試代碼:

#include <iostream> 
#include <boost/version.hpp> 
#include <boost/timer.hpp> 
using namespace std; 
int main() 
{ 
  boost::timer t; 
  cout << "max timespan: " << t.elapsed_max() / 3600 << "h" << endl; 
  cout << "min timespan: " << t.elapsed_min() << "s" << endl; 
  cout << "now time elapsed: " << t.elapsed() << "s" << endl; 
  cout << "boost version" << BOOST_VERSION <<endl; 
  cout << "boost lib version" << BOOST_LIB_VERSION <<endl; 
  return 0; 
} 

  

補充,在調用boost庫時,要加上連接選項-lboost_regex

如:g++ main.cc -lboost_regex


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM