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

posted @ 2018-07-24 11:24  CTHON  阅读(7237)  评论(0编辑  收藏  举报