windows-qt 使用mingw編譯c++boost並使用


一、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的使用

程序代碼入下:

 

[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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM