windows下mingw編譯boost

Mingw編譯Boost庫

1、Boost
Boost庫是一個可移植、提供源代碼的C++庫,做爲標準庫的後備,是C++標準化進程的發動機之一。其官方網站爲http://www.boost.org/,目前最新版本爲1.49.0,如下以此版本爲準。
Boost庫大部分的子庫都是C++模版提供,大部分狀況下直接包含頭文件就能夠了。其中部分子庫須要編譯,以下圖所示:

上圖中bjam.exe是boost提供的編譯工具,下面會介紹如何得到。html

Windows下面使用Boost,能夠下載編譯好的二進制安裝包,下載網址是: http://www.boostpro.com,不過目前上面提供1.44版的安裝包下載,並且使用VC編譯的。本文介紹如何使用Mingw編譯Boost。
2、Mingw: Minimalist GNU for Windows
官方網站: http://www.mingw.org/  部分同窗可能和我同樣,使用自帶Mingw環境的IDE,好比Code::Blocks,其官方網站: http://www.codeblocks.org/ 。請確保Mingw工具鏈目錄添加到系統的環境變量PATH中,好比我路徑爲:"D:\Program Files\CodeBlocks\MinGW\bin",並將這個目錄下的mingw32-make.exe複製並重命名爲make.exe。而後驗證gcc等可否正常使用:開始->運行->輸入"cmd"回車->命令窗口輸出"gcc -v"查看gcc版本信息,若是看到以下相似輸出,那麼就能夠繼續正是編譯Boost了。


3、bjam.exe
bjam是boost自帶的工具,用來方便地編譯boost,固然也能夠用來編譯你本身的工程。bjam在boost源碼中一塊兒提供,須要編譯才能使用,下載boost的時候會提示下載一個編譯好的bjam,我不是很推薦,由於我用下載來的bjam編譯boost的時候,出現一些錯誤,而用本身編譯的bjam卻順利完成。
在"E:\_Libs_\boost_1_46_0\tools\build\v2\engine\"下,使用命令"build mingw",會在此目錄下生成文件bin.ntx86\bjam.exe,將bjam.exe拷貝到boost源文件的根目錄下,如"E:\_Libs_\boost_1_46_0\"。在這個目錄下的"./Jamroot"文件,詳細描述了bjam的用法,建議用文本打開這個文件並閱讀前面部分的註釋,摘抄以下:
# Usage:
#
#   bjam [options] [properties] [install|stage]
#
#   Builds and installs Boost.
#
# Targets and Related Options:
#
#   install                 Install headers and compiled library files to the
#   =======                 configured locations (below).
#
#   --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>   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 a minimal set of 
#                               variants. On Windows, these are static 
#                               multithreaded libraries in debug and release
#                               modes, using shared runtime. On Linux, these
#                               are static and shared multithreaded libraries
#                               in release mode.
#
#                               complete - 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 - Names of boost binaries
#                               include the Boost version number, name and
#                               version of the compiler and encoded build
#                               properties.  Boost headers are installed in a
#                               subdirectory of <HDRDIR> whose name contains
#                               the Boost version number.
#
#                               tagged -- Names of boost binaries include the
#                               encoded build properties such as variant and
#                               threading, but do not including compiler name
#                               and version, or Boost version. This option is
#                               useful if you build several variants of Boost,
#                               using the same compiler.
#
#                               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.
#
#                           The default value is 'versioned' on Windows, and
#                           'system' on Unix.
#
#   --buildid=ID            Adds the specified ID to the name of built
#                           libraries.  The default is to not add anything.
#
#   --python-buildid=ID     Adds the specified ID to the name of built
#                           libraries that depend on Python.  The default 
#                           is to not add anything. This ID is added in 
#                           addition t --buildid.
#
#
#   --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.
#
#   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.


4、分享
bjam  --build-type=complete toolset=gcc stage
上面的命令將編譯全部須要編譯的子庫(除python)的各類版本,編譯時間稍長,約40分鐘~1小時。生成的文件在./stage/lib目錄下。 不一樣版本能夠經過名稱來區別,例如date_time庫一共生成有16個相關文件:
libboost_date_time-mgw44-1_46.a
libboost_date_time-mgw44-1_46.dll
libboost_date_time-mgw44-1_46.dll.a
libboost_date_time-mgw44-d-1_46.a
libboost_date_time-mgw44-d-1_46.dll
libboost_date_time-mgw44-d-1_46.dll.a
libboost_date_time-mgw44-mt-1_46.a
libboost_date_time-mgw44-mt-1_46.dll
libboost_date_time-mgw44-mt-1_46.dll.a
libboost_date_time-mgw44-mt-d-1_46.a
libboost_date_time-mgw44-mt-d-1_46.dll
libboost_date_time-mgw44-mt-d-1_46.dll.a
libboost_date_time-mgw44-mt-s-1_46.a
libboost_date_time-mgw44-mt-sd-1_46.a
libboost_date_time-mgw44-s-1_46.a
libboost_date_time-mgw44-sd-1_46.a
如上,mgw44表明編譯器Mingw4.4版本:
mt: threading=multi 
s: runtime-link=static
d: variant=debug
.dll: link=shared
.dll.a: 對應DLL的導入庫文件
相關文章
相關標籤/搜索