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

相關文章
相關標籤/搜索