一、boost是一个准标准库,相当于STL的延续和扩充,它的设计理念和STL比较接近,都是利用泛型让复用达到最大化。不过对比STL,boost更加实用。STL集中在算法部分,而boost包含了不少工具类,可以完成比较具体的工作。考虑到boost的强大,为此特地里做了windows下移植编译操作。

二、boost的移植

1.下载boost源码boost_1_62_0.7z,下载地址:https://sourceforge.NET/projects/boost/

其实也可以下载boos编译好的库和头文件,不过为了不必要的麻烦,建议手动编译

2.编译boost

1)解压boost到d盘,目录为boost_1_62

2)生成bjam工具:

进入D:\boost_1_62_0\boost_1_62_0\tools\build\src\engine目录下,执行build.sh gcc,在当前目录将会生成bin.ntx86文件夹,里面包含两个exe文件b2.exe,bjam.exe

3)将bin.ntx86\bjam.exe拷贝到boost1.37的解压目录D:\boost_1_62_0\boost_1_62_0中

4)进入路径D:\boost_1_62_0\boost_1_62_0,执行 bjam "toolset=gcc" install ,等待一段时间后,会在C盘根目录下生成一个boost文件夹,里面放着生成的头文件以及LIB和DLL文

5)将C:\Boost\include\boost-1_37目录下的boost文件夹拷贝到C:\MinGW\include下面

6)将C:\Boost\lib下的lib文件拷贝到C:\MinGW\lib,将C:\Boost\lib下的dll文件拷贝到C:\MinGW\bin

三、boost的使用

程序代码入下:

  1. #include <iostream>
  2. #include <boost/math/special_functions/acosh.hpp>
  3. #include <boost/math/special_functions/bessel.hpp>
  4. #include <string>
  5. #include <boost/filesystem.hpp>
  6. #include <boost/timer.hpp>
  7. using namespace boost::math;
  8. using namespace boost::math::detail;
  9. namespace fs = boost::filesystem;
  10. //测试boost贝塞尔函数
  11. void testBessel(){
  12. std::cout<<"Test Boost:"<<std::endl;
  13. std::cout<<acosh(2.5)<<std::endl;
  14. std::cout<<bessel_i0(3.2)<<std::endl;
  15. std::cout<<"Test Finished!"<<std::endl;
  16. }
  17. //测试boost文件系统库
  18. void testFileSystem(){
  19. fs::path full_path("c:");
  20. fs::directory_iterator end_iter;
  21. for ( fs::directory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr )
  22. {
  23. std::cout << dir_itr->path().filename() << std::endl;
  24. }
  25. }
  26. int main(int argc, char *argv[])
  27. {
  28. std::cout << "-----测试boost贝塞尔函数-------" << std::endl;
  29. testBessel();
  30. std::cout << "-----测试boost文件系统库------" << std::endl;
  31. testFileSystem();
  32. return 0;
  33. }

在xxx_pro中添加,

LIBS += -LC:\Qt\mingw\lib -lboost_system -lboost_filesystem

运行效果如下,

  1. Starting D:\Documents\build-cplusplusboost-unknown-Debug\debug\cplusplusboost.exe...
  2. -----测试boost贝塞尔函数-------
  3. Test Boost:
  4. 1.5668
  5. 5.74721
  6. Test Finished!
  7. -----测试boost文件系统库------
  8. "$RECYCLE.BIN"
  9. "Boost"
  10. "Boot"
  11. "bootmgr"
  12. "Documents and Settings"
  13. "PerfLogs"
  14. "Program Files"
  15. "Program Files (x86)"
  16. "ProgramData"
  17. "Qt"
  18. "RECYCLER"
  19. "System Volume Information"
  20. "Users"
  21. "Windows"

http://blog.csdn.net/xiaopangzi313/article/details/52800799

最新文章

  1. Adapt适配器
  2. note-&gt;notice
  3. 访问cv::Mat中的数据时遇到的指针类型问题
  4. COALESCE NVL NVL2 DECODE
  5. [MFC] MFC编译程序,缺少MFC动态链接库的解决
  6. Replication in Kafka
  7. MySQL--索引条件下推优化
  8. ZOJ Problem Set - 1002(DFS)
  9. Hadoop平台提供离线数据和Storm平台提供实时数据流
  10. Python自动化运维之3、函数、lambda、递归
  11. 【转】android service 之二(IntentService)
  12. 【Quick-COCOS2D-X 3.3 怎样绑定自己定义类至Lua之三】动手绑定自己定义类至Lua
  13. HTTP基础知识
  14. .NET面试题系列[16] - 多线程概念(1)
  15. iOS&amp;nbsp;动画总结—UIView动画
  16. Linux kernel的中断子系统之(六):ARM中断处理过程
  17. spring boot拦截器WebMvcConfigurerAdapter,以及高版本的替换方案
  18. 混合app开发,h5页面调用ios原生APP的接口
  19. IOS应用图标尺寸
  20. 《转》深入理解Activity启动流程(三)–Activity启动的详细流程1

热门文章

  1. 【b302】侦探推理
  2. Lua转让C功能
  3. 左右Cwnd::Create()功能出现afxwin1.inl line:21错误的解决方案
  4. Qt 元对象系统(Meta-Object System)(不管是否使用信号槽,都推荐使用)
  5. Android的PVPlayer介绍
  6. 各个版本 Windows 10 系统中自带的 .NET Framework 版本
  7. 微信公众平台消息接口开发(12)消息接口Bug
  8. σ 代数与测度(measures)
  9. phpstorm 删除空行
  10. WPF4文字模糊不清晰、边框线条粗细不一致的解决方法