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的使用
程序代碼入下:
- #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;
-
- 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;
- }
-
- 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"
http://blog.csdn.net/xiaopangzi313/article/details/52800799