天天看點

編譯Boost 詳細步驟 适用 VC6 VS2003 VS2005 VS2008 VS2010

vs2008編譯boost

【一、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,用模闆實作的元程式設計架構;

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

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

   (9)Pool,記憶體池管理;

   (10)smart_ptr,智能指針。

【二、Boost庫的編譯】

【Setp1 準備工作】:

(1)Boost 下載下傳可以到官方網站下載下傳:

<a href="http://www.boost.org/" target="_blank">http://www.boost.org/</a>

(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

完成後,可以使用。

【三、介紹Bjam使用】

Usage:

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

install                 Install  headers and compiled library files to the

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

                      在“--prefix=”指定的目錄下生成所有頭檔案

           (boost源代碼下boost檔案夾下所有檔案)和指定庫檔案

--prefix=&lt;PREFIX&gt;       Install architecture independent files here.

                     Default; C:/Boost on Win32

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

--exec-prefix=&lt;EPREFIX&gt;  Install architecture dependent files here.

                     Default; &lt;PREFIX&gt;

--libdir=&lt;DIR&gt;          Install library files here.

                     Default; &lt;EPREFIX&gt;/lib

--includedir=&lt;HDRDIR&gt;   Install header files here.

                      Default; &lt;PREFIX&gt;/include

stage                 Build and install only compiled library files

======               to the stage directory.

                          在“--stagedir=”指定的目錄下生成指定庫檔案

--stagedir=&lt;STAGEDIR&gt;   Install library files here

                      Default; ./stage

【Other Options】:

--build-type=&lt;type&gt;     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  &lt;threading&gt;multi  &lt;link&gt;shared

                     &lt;link&gt;static  &lt;runtime-link&gt;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=&lt;layout&gt;       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 &lt;HDRDIR&gt; 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 &lt;HDRDIR&gt;. 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-&lt;library&gt;                Build and install the specified &lt;library&gt;

                            If this option is used, only libraries

                            specified using this option will be built.

--without-&lt;library&gt;              Do not build, stage, or install the specified

                             &lt;library&gt;. 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=&lt;builddir&gt;

編譯的臨時檔案會放在builddir裡(編譯完就可以把它删除了)

--stagedir=&lt;stagedir&gt;

存放編譯後庫檔案的路徑,預設是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-&lt;library&gt;

隻編譯指定的庫,如輸入--with-regex就隻編譯regex庫了

--show-libraries

顯示需要編譯的庫名稱

【四、Bjam 生成檔案的分析】

(1)生成 Release 版本,多線程,動态連結C++标準庫 的regex 動态庫

 --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 動态庫

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

-- 輸出: 沒有這種配置

(3)生成 Release 版本,多線程,動态連結C++标準庫 的regex靜态庫

--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 靜态庫

 --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 靜态庫

 --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 靜态庫

 --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 動态庫

--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動态庫

--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”

繼續閱讀