vs2013編譯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 下載可以到官方網站下載:
(2)安裝VS2013 IDE
【Setp2 編譯Boost】
在使用vs2013編譯boost-1.55.0之前,先要給boost做下修改:
boost_1_55_0\boost\intrusive\detail\has_member_function_callable_with.hpp line:222
template<class U> static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) <U> Test(BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U>*);
替換成以下內容:
#ifdef BOOST_MSVC template<class U> static decltype(boost::move_detail::declval<Fun>().BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME() , boost_intrusive_has_member_function_callable_with::yes_type()) Test(Fun*); #else template<class U> static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) <U> Test(BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U>*); #endif
- 32位編譯:
- 從開始菜單啓動Visual Studio 2013的vs2013 命令行,進入boost所在目錄,運行bootstrap.bat
- 編譯命令:
bjam.exe stage --toolset=msvc-12.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-serialization --without-wave --without-test --without-program_options --without-serialization --without-signals --stagedir=".\bin\vc12_x86" link=static runtime-link=shared threading=multi debug release
- 64位編譯:
- 從開始菜單啓動Visual Studio 2013的vs2013 x64兼容工具命令行,然後轉到boost根文件夾,運行bootstrap.bat生成x64版的bjam.exe。
- 運行命令:
bjam.exe stage --toolset=msvc-12.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-serialization --without-wave --without-test --without-program_options --without-serialization --without-signals --stagedir=".\bin\vc12_x64" link=static runtime-link=shared threading=multi debug release address-model=64
【三、介紹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=debug|release |
決定編譯什麼版本(Debug or Release) |
link=static|shared |
決定使用靜態庫還是動態庫 |
threading=single|multi |
決定使用單線程還是多線程庫 |
runtime-link=static|shared |
決定是靜態還是動態鏈接C/C++標準庫 |
--with-<library> |
只編譯指定的庫,如輸入--with-regex就只編譯regex庫了 |
--show-libraries |
顯示需要編譯的庫名稱 |
【四、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”