windows-qt 使用mingw编译c++boost并使用
2016-10-12 21:39
471 查看
一、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的使用
程序代码入下:
#include <iostream>
#include <boost/math/special_functions/acosh.hpp>
#include <boost/math/special_functions/bessel.hpp>
#include <string>
#include <boost/filesystem.hpp>
#include <boost/timer.hpp>
using namespace boost::math;
using namespace boost::math::detail;
namespace fs = boost::filesystem;
//测试boost贝塞尔函数
void testBessel(){
std::cout<<"Test Boost:"<<std::endl;
std::cout<<acosh(2.5)<<std::endl;
std::cout<<bessel_i0(3.2)<<std::endl;
std::cout<<"Test Finished!"<<std::endl;
}
//测试boost文件系统库
void testFileSystem(){
fs::path full_path("c:");
fs::directory_iterator end_iter;
for ( fs::directory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr )
{
std::cout << dir_itr->path().filename() << std::endl;
}
}
int main(int argc, char *argv[])
{
std::cout << "-----测试boost贝塞尔函数-------" << std::endl;
testBessel();
std::cout << "-----测试boost文件系统库------" << std::endl;
testFileSystem();
return 0;
}
在xxx_pro中添加,
运行效果如下,
Starting D:\Documents\build-cplusplusboost-unknown-Debug\debug\cplusplusboost.exe...
-----测试boost贝塞尔函数-------
Test Boost:
1.5668
5.74721
Test Finished!
-----测试boost文件系统库------
"$RECYCLE.BIN"
"Boost"
"Boot"
"bootmgr"
"Documents and Settings"
"PerfLogs"
"Program Files"
"Program Files (x86)"
"ProgramData"
"Qt"
"RECYCLER"
"System Volume Information"
"Users"
"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的使用
程序代码入下:
#include <iostream>
#include <boost/math/special_functions/acosh.hpp>
#include <boost/math/special_functions/bessel.hpp>
#include <string>
#include <boost/filesystem.hpp>
#include <boost/timer.hpp>
using namespace boost::math;
using namespace boost::math::detail;
namespace fs = boost::filesystem;
//测试boost贝塞尔函数
void testBessel(){
std::cout<<"Test Boost:"<<std::endl;
std::cout<<acosh(2.5)<<std::endl;
std::cout<<bessel_i0(3.2)<<std::endl;
std::cout<<"Test Finished!"<<std::endl;
}
//测试boost文件系统库
void testFileSystem(){
fs::path full_path("c:");
fs::directory_iterator end_iter;
for ( fs::directory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr )
{
std::cout << dir_itr->path().filename() << std::endl;
}
}
int main(int argc, char *argv[])
{
std::cout << "-----测试boost贝塞尔函数-------" << std::endl;
testBessel();
std::cout << "-----测试boost文件系统库------" << std::endl;
testFileSystem();
return 0;
}
在xxx_pro中添加,
LIBS += -LC:\Qt\mingw\lib -lboost_system -lboost_filesystem
运行效果如下,
Starting D:\Documents\build-cplusplusboost-unknown-Debug\debug\cplusplusboost.exe...
-----测试boost贝塞尔函数-------
Test Boost:
1.5668
5.74721
Test Finished!
-----测试boost文件系统库------
"$RECYCLE.BIN"
"Boost"
"Boot"
"bootmgr"
"Documents and Settings"
"PerfLogs"
"Program Files"
"Program Files (x86)"
"ProgramData"
"Qt"
"RECYCLER"
"System Volume Information"
"Users"
"Windows"
相关文章推荐
- windows-qt 使用mingw编译c++boost并使用
- 在Windows环境下使用MinGW编译Qt 4.8.6
- QT5.10开发(2) 在Windows 10下使用MinGW编译 静态Qt 5.10 release版 详细过程
- 在Windows环境下使用MinGW编译Qt 4.8.6
- 在Windows 10下使用MinGW静态编译Qt 5.9.1的详细过程(Ver 17.0819)
- Linux下编译静态MinGW环境,编译windows平台Qt程序(使用MXE)
- Windows系统使用minGW+msys 编译ffmpeg 0.5的全过程详述
- 在Windows中使用MinGW编译X264
- 使用mingw 与 vs 编译64位的QT 库
- windows下使用MinGW+msys编译ffmpeg,以及如何加入eclipse CDT调试
- windows 下 Qt4.8编译oracle数据库OCI驱动 并使用
- windows下使用MinGW+msys编译ffmpeg
- Windows 系统下使用 MinGW + MSYS + GCC 编译 FFMPEG
- Windows 系统下使用 MinGW + MSYS + GCC 编译 FFMPEG
- windows下使用MinGW+msys编译ffmpeg
- windows下使用MinGW+msys编译ffmpeg
- Windows + MinGW环境下使用libxml2 (1) 安装已编译包
- cscope在windows下使用mingw编译的方法
- windows下使用MinGW编译QPSQL插件
- Qt4.7.3(MinGW Opensource版)windows编译mysql驱动