搜索boost官网:
https://www.boost.org/ 可下载最新库。
参考:https://www.cnblogs.com/findumars/p/6253092.html
1、解压
tar -zxvf boost_1_69_0.tar.gz
2、编译
进入boost_1_69_0目录中
cd boost_1_69_0
./bootstrap.sh --with-libraries=all --with-toolset=gcc
--with-liraries:需要编译的库
--with-toolset:编译时使用的编译器
根据提示输入编译
./b2
3、安装
./b2 --prefix=/usr/local/boost install
将boost库添加至环境变量。输入命令:gedit /etc/environment
CPLUS_INCLUDE_PATH=/usr/local/boost/include
LIBRARY_PATH=/usr/local/boost/lib
重启生效。
4、测试
#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++ testBoost.cpp -o testBoost
运行:./testBoost