編譯Boost 詳細步驟

vs2008編譯boostpython

 

【1、Boost庫的介紹】正則表達式

Boost庫是一個通過千錘百煉、可移植、提供源代碼的C++庫,做爲標準庫的後備,是C++標準化進程的發動機之一。 Boost庫由C++標準委員會庫工做組成員發起,其中有些內容有望成爲下一代C++標準庫內容。在C++社區中影響甚大,其成員已近2000人。 Boost庫爲咱們帶來了最新、最酷、最實用的技術,是徹徹底底的「準」標準庫。算法

   Boost庫中比較有名的幾個庫:編程

   (1)Regex,正則表達式庫;多線程

   (2)Spirit,LL parser framework,用C++代碼直接表達EBNF;框架

   (3)Graph,圖組件和算法;函數

   (4)Lambda,在調用的地方定義短小匿名的函數對象,很實用的functional功能;性能

   (5)concept check,檢查泛型編程中的concept;網站

   (6)Mpl,用模板實現的元編程框架;ui

   (7)Thread,可移植的C++多線程庫;

   (8)Python,把C++類和函數映射到Python之中;

   (9)Pool,內存池管理;

   (10)smart_ptr,智能指針。

 

 

【2、Boost庫的編譯】

【Setp1 準備工做】:

(1)Boost 下載能夠到官方網站下載:

http://www.boost.org/

 

(2)安裝VS2008 IDE

 

 

【Setp2 編譯Boost】

1.打開Visual Studio 2008 命令提示窗口

2.進入D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\boost_1_44_0\tools\jam\src

3.執行 build.bat 會在D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\boost_1_44_0

\tools\jam\src\bin.ntx86 生成 bjam.exe文件.

4.Copy bjam.exe 文件到 D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\boost_1_44_0 下

6.進入D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\boost_1_44_0 目錄

7.執行bjam.exe 編譯命令,以下:

 

 

(1)編譯全部boost動態庫 (release|debug),包括頭文件和庫文件

bjam --toolset=msvc-9.0 --prefix=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output --without-python --build-type=complete  link=shared  threading=multi install

 

(2)只編譯 release 版本 regex 動態庫,包括頭文件和庫文件

bjam --toolset=msvc-9.0 --prefix=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output1 --with-regex link=shared  threading=multi variant=release runtime-link=shared  install

 

(3)只編譯 release 版本 regex 動態庫,包括庫文件

bjam --toolset=msvc-9.0

--stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output2

--with-regex link=shared  threading=multi variant=release runtime-link=shared  stage

 

 

【注意】: Boost 源代碼所在路徑最好全英文,不要有空格、特殊字符、中文等

 

編譯要花上30分鐘左右(根據PC性能所定), 會在指定生成目錄:

D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output下生成對應庫文件和頭文件。

 

8.設置開發環境

打開VS2008 建立工程, 配置工程屬性

設置包含文件目錄F:\Develop\BoostlibAndDll\include\boost-1_37\boost

設置引用文件目錄:F:\Develop\BoostlibAndDll\lib

完成後,可使用。

 

 

【3、介紹Bjam使用】

Usage:

Bjam  [options]  [properties]  [install|stage]

 

 

install                 Install  headers and compiled library files to the

=======               configured locations (below).

                      在「--prefix=」指定的目錄下生成全部頭文件

           (boost源代碼下boost文件夾下全部文件)和指定庫文件

 

--prefix=<PREFIX>       Install architecture independent files here.

                     Default; C:\Boost on Win32

                     Default; /usr/local on Unix. Linux, etc.

 

--exec-prefix=<EPREFIX>  Install architecture dependent files here.

                     Default; <PREFIX>

 

--libdir=<DIR>          Install library files here.

                     Default; <EPREFIX>/lib

 

--includedir=<HDRDIR>   Install header files here.

                      Default; <PREFIX>/include

 

stage                 Build and install only compiled library files

======               to the stage directory.

                          在「--stagedir=」指定的目錄下生成指定庫文件

 

 

--stagedir=<STAGEDIR>   Install library files here

                      Default; ./stage

 

 

【Other Options】:

--build-type=<type>     Build the specified pre-defined set of variations

                     of the libraries. Note, that which variants get

                     built depends on what each library supports.

 

                     minimal (default) - Builds the single

                     "release" version of the libraries. This

                     release corresponds to specifying:

                     "release  <threading>multi  <link>shared

                     <link>static  <runtime-link>shared" as the

                     Build variant to build.

                     complete - Attempts to build all possible

                     variations.

 

--build-dir=DIR         Build in this location instead of building

                     within the distribution tree. Recommended!

 

--show-libraries        Displays the list of Boost libraries that require

                     build and installation steps, then exit.

 

--layout=<layout>       Determines whether to choose library names

                     and header locations such that multiple

                     versions of Boost or multiple compilers can

                     be used on the same system.

 

                     versioned (default) - Names of boost

                     binaries include the Boost version

                     number and the name and version of the

                     compiler. Boost headers are installed

                     in a subdirectory of <HDRDIR> whose

                     name contains the Boost version number.

 

                     system - Binaries names do not include

                     the Boost version number or the name

                     and version number of the compiler.

                     Boost headers are installed directly

                     into <HDRDIR>. This option is

                     intended for system integrators who

                     are building distribution packages.

 

--buildid=ID                    Adds the specified ID to the name of built

                        libraries. The default is to not add anything.

 

--help                     This message.

 

--with-<library>                Build and install the specified <library>

                            If this option is used, only libraries

                            specified using this option will be built.

 

--without-<library>              Do not build, stage, or install the specified

                             <library>. By default, all libraries are built.

 

 

【Properties】:

toolset=toolset            Indicates the toolset to build with.

                                                        msvc-6.0 :  VC6.0

msvc-7.0:  VS2003

                                                        msvc-8.0:  VS2005

                                                        msvc-9.0:  VS2008

                                                        msvc-10.0:  VS2010

 

variant=debug|release      Select the build variant

 

link=static|shared          Whether to build static or shared libraries

 

threading=single|multi      Whether to build single or multithreaded binaries

 

runtime-link=static|shared   Whether to link to static or shared C and C++ runtime.

                         決定是靜態仍是動態連接C/C++標準庫

 

 

Bjam 選項、參數說明
 
--build-dir=<builddir>
 編譯的臨時文件會放在builddir裏(編譯完就能夠把它刪除了)
 
--stagedir=<stagedir>
 存放編譯後庫文件的路徑,默認是stage
 
--build-type=complete
 編譯全部版本,否則只會編譯一小部分版本(至關於:
variant=release,threading=multi;
link=shared|static;runtime-link=shared)
 
variant=debug|release
 決定編譯什麼版本(Debug or Release)
 
link=static|shared
 決定使用靜態庫仍是動態庫
 
threading=single|multi
 決定使用單線程仍是多線程庫
 
runtime-link=static|shared
 決定是靜態仍是動態連接C/C++標準庫
 
--with-<library>
 只編譯指定的庫,如輸入--with-regex就只編譯regex庫了
 
--show-libraries
 顯示須要編譯的庫名稱
 

 

 

 

【4、Bjam 生成文件的分析】

 

(1)生成 Release 版本,多線程,動態連接C++標準庫 的regex 動態庫

bjam --toolset=msvc-9.0

 --stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output2

--with-regex   link=shared  threading=multi  variant=release  runtime-link=shared  stage

 

-- 輸出: boost_regex-vc90-mt.lib

boost_regex-vc90-mt-1_44.lib

                boost_regex-vc90-mt-1_44.dll

 

 

(2)生成 Release 版本,多線程,靜態連接C++標準庫 的regex 動態庫

bjam --toolset=msvc-9.0

 --stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output2

--with-regex   link=shared  threading=multi  variant=release  runtime-link= static  stage

 

-- 輸出: 沒有這種配置

 

 

(3)生成 Release 版本,多線程,動態連接C++標準庫 的regex靜態庫

bjam --toolset=msvc-9.0

 --stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output2

--with-regex   link= static  threading=multi  variant=release  runtime-link=shared  stage

 

-- 輸出: libboost_regex-vc90-mt-s.lib

libboost_regex-vc90-mt-1_44.lib

 

 

 

(4)生成 Release 版本,多線程,靜態連接C++標準庫 的regex 靜態庫

bjam --toolset=msvc-9.0

 --stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output3

--with-regex  link=static  threading=multi  variant=release  runtime-link=static  stage

 

-- 輸出:libboost_regex-vc90-mt-s.lib

libboost_regex-vc90-mt-s-1_44.lib

 

 

 

--------------------------------------------------------------------------------------------------------------------

 

(1)生成 Debug 版本,多線程,動態連接C++標準庫 的regex 靜態庫

bjam --toolset=msvc-9.0

 --stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output4

--with-regex  link=static  threading=multi  variant=debug runtime-link=shared  stage

 

-- 輸出: libboost_regex-vc90-mt-gd.lib

libboost_regex-vc90-mt-gd-1_44.lib

 

 

 

(2)生成 Debug 版本,多線程,靜態連接C++標準庫 的regex 靜態庫

bjam --toolset=msvc-9.0

 --stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output5

--with-regex   link=static  threading=multi  variant=debug  runtime-link=static  stage

 

-- 輸出: libboost_regex-vc90-mt-sgd.lib

libboost_regex-vc90-mt-sgd-1_44.lib

 

 

(3)生成 Debug 版本,多線程,動態連接C++標準庫 的regex 動態庫

bjam --toolset=msvc-9.0

 --stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output5

--with-regex   link=shared  threading=multi  variant=debug  runtime-link=shared  stage

 

- 輸出: boost_regex-vc90-mt-gd.lib

boost_regex-vc90-mt-gd-1_44.lib

         boost_regex-vc90-mt-gd-1_44.dll

 

 

(4)生成 Debug 版本,多線程,靜態連接C++標準庫 的regex動態庫

bjam --toolset=msvc-9.0

 --stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output5

--with-regex   link=shared  threading=multi  variant=debug  runtime-link=static  stage

 

-- 輸出:沒有這種配置

 

 

【總結】:

(1)       編譯成功後,Bjam 都會給你生成一對同樣的導入庫文件或者靜態庫文件(以下),

惟一不一樣的是兩個文件名稱一個在後面加上了boost版本信息, 爲了讓用戶知道使用的boost的版本信息。

 

 boost_regex-vc90-xxxxx.lib

 boost_regex-vc90-xxxxx-1_44.lib

 

(2)       Bjam編譯選項 有4個, 理論上應該有 2*2*2*2 = 16 種配置

ink= static| shared 

threading= single |multi 

variant=release|debug 

runtime-link= static |shared

 

實際使用的多爲多線程, 因此 threading= multi, 這樣剩下的3個選項組成的編譯配置就是上面所羅列的, 其中靜態連接C++標準庫的boost動態庫這種配置也不存在, 因此就只有4種狀況。

 

(3)

          link= static : 靜態庫。 生成的庫文件名稱以 「lib」開頭

link= shared : 動態庫。生成的庫文件名稱無「lib」開頭

 

threading= mult : 支持多線程。 生成的庫文件名稱中包含 「-mt」

 

variant=release  生成的庫文件名稱不包含 「-gd」

variant= debug  生成的庫文件名稱包含 「-gd」

 

runtime-link= static  生成的庫文件名稱包含 「-s」

runtime-link= shared  生成的庫文件名稱不包含 「-s」

相關文章
相關標籤/搜索