zoukankan      html  css  js  c++  java
  • 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:oost_1_62_0oost_1_62_0 oolsuildsrcengine目录下,执行build.sh gcc,在当前目录将会生成bin.ntx86文件夹,里面包含两个exe文件b2.exe,bjam.exe

    3)将bin.ntx86jam.exe拷贝到boost1.37的解压目录D:oost_1_62_0oost_1_62_0中

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

    5)将C:Boostincludeoost-1_37目录下的boost文件夹拷贝到C:MinGWinclude下面

    6)将C:Boostlib下的lib文件拷贝到C:MinGWlib,将C:Boostlib下的dll文件拷贝到C:MinGWin

    三、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:Qtmingwlib -lboost_system -lboost_filesystem

    运行效果如下,

    [cpp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. Starting D:Documentsuild-cplusplusboost-unknown-Debugdebugcplusplusboost.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

  • 相关阅读:
    C#操作REDIS例子
    A C# Framework for Interprocess Synchronization and Communication
    UTF8 GBK UTF8 GB2312 之间的区别和关系
    开源项目选型问题
    Mysql命令大全——入门经典
    RAM, SDRAM ,ROM, NAND FLASH, NOR FLASH 详解(引用)
    zabbix邮件报警通过脚本来发送邮件
    centos启动提示unexpected inconsistency RUN fsck MANUALLY
    rm 或者ls 报Argument list too long
    初遇Citymaker (六)
  • 原文地址:https://www.cnblogs.com/findumars/p/6375658.html
Copyright © 2011-2022 走看看