您的位置:首页 > 其它

boost 库的下载和编译_Visual Studio 2013(转)

2017-06-11 21:10 381 查看
原文转自 http://blog.csdn.net/lp310018931/article/details/47791143

原文转自 http://m.blog.csdn.net/article/details?id=42265605

Boost库是一个可移植、提供源代码的C++库,作为标准库的后备,是C++标准化进程的开发引擎之一。 Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成为下一代C++标准库内容。在C++社区中影响甚大,是不折不扣的“准”标准库。Boost由于其对跨平台的强调,对标准C++的强调,与编写平台无关。大部分boost库功能的使用只需包括相应头文件即可,少数(如正则表达式库,文件系统库等)需要链接库。但Boost中也有很多是实验性质的东西,在实际的开发中实用需要谨慎。

1、首先到boost官网去下载最新版本的boost库,本人下载的是boost_1_64_0.zip:

http://www.boost.org/

2、解压后,以管理员方式在命令提示符下运行cmd, 进入 E:\WinClient\boost_1_64_0\目录,运行 bootstrap.bat批处理文件,运行后会在E:\WinClient\boost_1_64_0\目录中出现bjam.exe文件

3、然后在cmd中输入如下命令即可:

bjam.exe stage --toolset=msvc-12.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-serialization --without-wave --without-test --without-program_options --without-serialization --without-signals --link=static runtime-link=static threading=multi debug release


等待程序编译完成,会在boost根目录下生成bin.v2和stage两个文件夹,其中bin.v2下是生成的中间文件,大小在2.7G左右,可以直接删除。stage下才是生成的dll和lib文件。

注意:如果编译时用下面的指令,则会生成所有的带s的库和不带s的库

bjam.exe stage --toolset=msvc-12.0 --build-type=complete --without-graph --without-graph_parallel --without-math --without-mpi --without-serialization --without-wave --without-test --without-program_options --without-serialization --without-signals


4、打开Visual Studio:

工程-->属性-->VC++目录:"包含目录(Include)": boost的根目录,例: D:\Visual Stdio 2013\lipeng\boost\boost_1_58_0

"库目录(Lib)": stage下的链接库目录,例:D:\Visual Stdio 2013\lipeng\boost\boost_1_58_0\stage\lib

通用属性->链接器->常规:"附加库目录":同上面的"库目录",例:D:\Visual Stdio 2013\lipeng\boost\boost_1_58_0\stage\lib

至此环境就配置好了,下面测试一下:

<span style="font-size:14px;"><pre name="code" class="cpp"><span style="font-family:Courier New;">#include <cstdlib>

#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <boost/thread.hpp>
#include <boost/timer.hpp>
#include <boost/progress.hpp>

#include <libs/date_time/src/gregorian/greg_names.hpp>
#include <libs/date_time/src/gregorian/date_generators.cpp>
#include <libs/date_time/src/gregorian/greg_month.cpp>
#include <libs/date_time/src/gregorian/gregorian_types.cpp>

#include <boost/date_time/posix_time/posix_time.hpp>

using namespace boost;

int main()
{
boost::timer t;

boost::progress_display pd(100);

for (int i = 0; i < 100; ++i) //进度条
{
++pd;
}

boost::gregorian::date dt(2009, 12, 8); //date_time 库
assert(dt.year() == 2009);
assert(dt.day() == 8);
boost::gregorian::date::ymd_type ymd = dt.year_month_day();
std::cout<<"\n"<<ymd.year<<"/"<<ymd.month<<"/"<<ymd.day<<" the day is "
<<dt.day_of_year() <<" days of this year"<< std::endl;

std::cout << boost::gregorian::to_iso_extended_string(dt) << std::endl; //转换为其他格式
std::cout << boost::gregorian::to_iso_string(dt) << std::endl;
std::cout << boost::gregorian::to_simple_string(dt) << std::endl<<std::endl;

//对数组排序操作
std::vector<int> test_vc(100);
std::vector<int>::iterator beg_it = test_vc.begin();
std::vector<int>::iterator end_it = test_vc.end();
std::srand(std::time(NULL));

std::for_each(beg_it, end_it, [](int& n){n = rand(); });
std::copy(beg_it, end_it, std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl << std::endl;
std::sort(beg_it, end_it, std::greater<int>());
std::copy(beg_it, end_it, std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl<<std::endl;

boost::posix_time::ptime pt(boost::gregorian::date(2005, 2, 6));

std::cout << t.elapsed() << "s" << std::endl; //程序运行时间

system("pause");

return 0;
}</span></span>


5、程序编译崩溃,解决方法是:安装VS2013的update5补丁包。

6、重新编译后,程序正确运行:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: