如何編譯 boost 的 library For Visual Studio

步驟

Step 1: 下載並解壓縮

link: http://sourceforge.net/projects/boost/files/boost/1.56.0/

Step 2: 打開 boost 資料夾,點兩下 bootstrap.bat

這是一個專為 Windows 設計的解本,會把 compile 的環境建置好。

Step 3: 把下面的 bat 腳本存在 boost 根目錄資料夾下,點兩下執行它。

b2 --build-type=complete stage ^
   install --prefix=my_build_dir ^
   toolset=msvc ^
   link=static,shared ^
   threading=multi ^
   runtime-link=static,shared^
   --with-test ^
   --variant=debug,release ^
   address-model=64

Step 4: 好了。

設定檔解釋

ps. ^ 是 Dos 的換行符號

  • b2 --build-type=complete stage ^

    主要編譯程式

  • install --prefix=my_build_dir

    輸出的資料夾

  • toolset=msvc

    使用 Microsoft 的環境編譯

  • link=static,shared

    產出 static:lib, shared:dll

  • threading=multi

    multi-thread 支援

  • runtime-link=static,shared

    產出使用 static: 靜態, shared: 動態的 C/C++ Runtime Library。也就是 Visual Studio 所謂的 /MT 跟 /MD

  • --with-test

    只編譯 unittest 的 Module,否則他會全部編完,會很久很久...

  • --variant=debug,release

    debug 版跟 release 版

  • address-model=64

    64 版本, 32 版本請打 32

ref: http://www.boost.org/doc/libs/1_56_0/more/getting_started/windows.html
http://www.boost.org/boost-build2/doc/html/bbv2/overview/invocation.html

Library 版本解譯

libboost_unit_test_framework-vc110-mt-sgd-1_56.lib

以下是網頁照抄:

lib
Prefix: except on Microsoft Windows, every Boost library name begins with this string. On Windows, only ordinary static libraries use the lib prefix; import libraries and DLLs do not.5
boost_regex
Library name: all boost library filenames begin with boost_.

-vc110
Toolset tag: identifies the toolset and version used to build the binary.

-mt
Threading tag: indicates that the library was built with multithreading support enabled. Libraries built without multithreading support can be identified by the absence of -mt.

s linking statically to the C++ standard library and compiler runtime support libraries. runtime-link=static

g using debug versions of the standard and runtime support libraries. runtime-debugging=on

d building a debug version of your code.6 variant=debug

http://www.boost.org/doc/libs/1_56_0/more/getting_started/windows.html

該用哪一個?

用 DLL

  • debug 版: boost_unit_test_framework-vc110-mt-gd-1_56.dll
  • release 版: boost_unit_test_framework-vc110-mt-1_56.dll

用 Runtime 是 DLL 的 Lib

  • debug 版: boost_unit_test_framework-vc110-mt-gd-1_56.lib
  • release 版: boost_unit_test_framework-vc110-mt-1_56.lib

用 Runtime 是 static 的,且無 Runtime Debug 支援。

  • debug 版: libboost_unit_test_framework-vc110-mt-gd-1_56.lib
  • release 版: libboost_unit_test_framework-vc110-mt-1_56.lib

用 Runtime 是 static 的,且有 Runtime Debug 支援。

  • debug 版: libboost_unit_test_framework-vc110-mt-sgd-1_56.lib
  • release 版: libboost_unit_test_framework-vc110-mt-s-1_56.lib

繼續建置 Boost Unittest 環境 ->
http://ot-note.logdown.com/posts/197872/c-unit-test-using-boostunittest-on-visual-studio

comments powered by Disqus