windows下boost库的基本使用方法

网友投稿 1380 2022-09-19

windows下boost库的基本使用方法

windows下boost库的基本使用方法

因为boost都是使用模板的技术,所以所有代码都是写在一个.hpp头文件中。这样boost中的大部分内容是不需要编译生成相应的链接库,只需要设置下面的包含目录(或者设置一下环境变量),在源文件中包含相应的头文件就可以使用了。少部分库需要生成链接库来使用。

下面介绍完整安装boost库的方法:

1、首先到boost官网去-最新的版本的boost库:

2、解压文件,在命令提示符中打开到boost库的根目录下:

双击bootstrap.bat文件,生成bjam.exe,执行以下命令:

bjam --toolset=msvc --build-type=complete stage

或者直接双击bjam.exe.

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

3、打开vs:

视图->属性管理器->当前项目->Debug|Win32->Microsoft.Cpp.Win32.user双击

在弹出的属性对话框中:

通用属性->VC++目录:"包含目录": boost的根目录,例: D:\Visual Stdio 2013\lipeng\boost\boost_1_58_0

"库目录": 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

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

[cpp] view plain copy #include       #include    #include    #include    #include       #include    #include       #include    #include    #include    #include       #include       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"< test_vc(100);       std::vector::iterator beg_it = test_vc.begin();       std::vector::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(std::cout, " "));       std::cout << std::endl << std::endl;       std::sort(beg_it, end_it, std::greater());       std::copy(beg_it, end_it, std::ostream_iterator(std::cout, " "));       std::cout << std::endl<

程序正确运行:

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:关于Windows中的硬链接
下一篇:Python2代码转成Python3代码(怎么把python2代码转换为python3)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~