apt-get install libbz2-dev #如果编译出现错误:bzlib.h: No such file or directory
上述函数库装好之后,就可以编译boost库了。解压boost_1_57_0.tar.gz:
tar zxvf boost_1_57_0.tar.gz sudo mv boost_1_57_0 /usr/local/修改权限:
chmod -R 755 /usr/local/boost_1_57转到boost根目录,执行脚本:
sudo ./bootstrap.sh sudo ./bjam --with-date_time //只编译了date_time
编译完成的提示,根据提示配置codeblocks
codeblocks菜单栏setting->compiler->Search directories
在compiler下添加:/usr/local/boost_1_57_0
在linker下添加:/usr/local/boost_1_57_0/stage/lib
测试代码:
#include <iostream> #include<thread> #include<chrono> #include<clocale> #include "boost/date_time/gregorian/gregorian.hpp" #include "boost/date_time/posix_time/posix_time.hpp" using namespace std; using namespace boost; using namespace boost::gregorian; using namespace boost::posix_time; int main() { date d = day_clock::local_day(); date_facet* dfacet = new date_facet("%Y年%m月%d日"); cout.imbue(locale(cout.getloc(), dfacet)); cout << d << endl; ptime tp = microsec_clock::local_time(); time_facet* tfacet = new time_facet("%Y年%m月%d日%H点%M分%S%F秒"); cout.imbue(locale(cout.getloc(), tfacet)); cout << tp << endl; return 0; }