windows-qt 使用mingw编译c++boost并使用

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

2、boost的移植算法

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

   其实也能够下载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.exeui

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

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

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

3、boost的使用

程序代码入下:

 

[cpp]  view plain  copy
 
 在CODE上查看代码片派生到个人代码片
  1. #include <iostream>  
  2. #include <boost/math/special_functions/acosh.hpp>  
  3. #include <boost/math/special_functions/bessel.hpp>  
  4.   
  5. #include <string>  
  6. #include <boost/filesystem.hpp>  
  7.   
  8. #include <boost/timer.hpp>  
  9.   
  10. using namespace boost::math;  
  11. using namespace boost::math::detail;  
  12. namespace fs = boost::filesystem;  
  13.   
  14. //测试boost贝塞尔函数  
  15. void testBessel(){  
  16.     std::cout<<"Test Boost:"<<std::endl;  
  17.   
  18.     std::cout<<acosh(2.5)<<std::endl;  
  19.   
  20.     std::cout<<bessel_i0(3.2)<<std::endl;  
  21.   
  22.     std::cout<<"Test Finished!"<<std::endl;  
  23. }  
  24.   
  25. //测试boost文件系统库  
  26. void testFileSystem(){  
  27.     fs::path full_path("c:");  
  28.     fs::directory_iterator end_iter;  
  29.     for ( fs::directory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr )  
  30.     {  
  31.         std::cout << dir_itr->path().filename() << std::endl;  
  32.     }  
  33. }  
  34.   
  35.   
  36.   
  37. int main(int argc, char *argv[])  
  38. {  
  39.     std::cout << "-----测试boost贝塞尔函数-------" << std::endl;  
  40.     testBessel();  
  41.   
  42.     std::cout << "-----测试boost文件系统库------" << std::endl;  
  43.     testFileSystem();  
  44.   
  45.     return 0;  
  46. }  

在xxx_pro中添加,

 

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

运行效果以下,

 

 

[cpp]  view plain  copy
 
 在CODE上查看代码片派生到个人代码片
  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

相关文章
相关标签/搜索