一、下载Boost库
下载地址:https://www.boost.org/users/download/
二、编译Boost库
cd boost_1_72_0
./bootstrap.sh --with-python=python2.7
# 修改Python2.7的路径,改为:/usr/include/python2.7
vim project-config.jam
# 将boost库相关文件安装至/usr/local
sudo ./b2 --prefix=/usr/local/boost install
sudo vim /etc/profile # 添加环境变量
# 增加如下路径
CPLUS_INCLUDE_PATH=/usr/local/boost/include
LIBRARY_PATH=/usr/local/boost/lib
source /etc/profile # 使环境变量生效
三、使用Boost库
#include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
using namespace std;
int main()
{
boost::gregorian::date d(boost::gregorian::day_clock::local_day());
cout << d.year()<<"." << d.month()<<"." <<d.day() <<endl;
getchar();
return 0;
}
g++ -I /usr/local/boost/include -L /usr/local/boost/lib test_Boost.cpp -o test_Boost