編譯 Boost 1.35.0 (Visual Studio 2005 (VC 8.0) + Windows XP)

簡介

  1. Boost 的原始碼可以在官網 http://www.boost.org 找到,或是直接到 sourceforge 下載,網址是:http://tinyurl.com/m7jqo
  2. Boost 有著自己一套的建置系統,叫做 Boost.Build [1],可用在編譯、 安裝、測試等功能上。Boost.Build 則是架構於 Boost.Jam, Boost.Jam 又是 Perforce Jam[2] 的衍生,更詳細的介紹可以在 [3] 看到。
  3. 通常在 Windows 上安裝 Boost ,最快速、簡易的方法是去 Boost Consulting 下載 installer [4],不過到今天為止, Boost 1.35.0 的 installer 都還沒 release。所以大家來學學自己編譯吧 : )
  4. Boost Getting Started on Windows [5] 是一篇官方的教學文件,有簡易的 bjam 使用方法,但無註明完整安裝的步驟,另外它也簡介了Boost Project 的 layout, simple usage 等等。
  5. Boost 身為最先進、標準的 C++ library ,它大量使用了 generic programming, metaprogramming 等技巧,使得實際上需要編譯成函式庫(.lib, .dll)的部份反而少了,根據 Boost Getting Started on Windows [5] 的說明,只有以下幾個 library 使用時,一定需要先編譯成函式庫(.lib, .dll):
    1. Boost.Filesystem
    2. Boost.IOStreams
    3. Boost.ProgramOptions
    4. Boost.Python
    5. Boost.Regex
    6. Boost.Serialization
    7. Boost.Signals
    8. Boost.Thread
    9. Boost.Wave

    還有幾個則是 optional:

    1. Boost.DateTime
    2. Boost.Graph
    3. Boost.Test

安裝步驟

  1. 下載 source code 並解壓縮。
  2. 使用 Open Visual Studio 2005 Command Prompt 進入 cmd。利用 Open Visual Studio 2005 Command Prompt 的原因有兩點:
    1. 方便呼叫 namke, cl 等 vc toolchain。
    2. 若是電腦上安裝多個編譯器,使用 Open Visual Studio 2005 Command Prompt 通常可透過環境變數,讓 bjam 使用正確的 toolchain。
  3. 取得 bjam.exe。
    1. 可以選擇到 Boost 提供的預先編譯好的 binary,可在http://tinyurl.com/2q36f 下載。
    2. 或是自行編譯,以下是編譯步驟:
      1. $> cd your_dir\boost_1_35_0\tools\jam\src
      2. $> build.bat
      3. 執行完後,boost_1_35_0\tools\jam\src\bin.ntx86 下就放著編譯完後的 bjam.exe 了!
  4. 將上一個步驟的 bjam.exe 放入 PATH 環境變數或是使用絕對路徑呼叫 bjam,並搭配以下的 options 就可開始編譯並安裝 boost:
    • $> bjam.exe --build-dir="your_dir\boost_1_35_0" --build-type=complete --toolset=msvc install
    • --build-dir: boost 解壓縮的檔案,記得 = 前後不可有空白!
    • --build-type: complete 會產生 release, debug ,以及各種設定的對應:如 multithread, debug, 等等。
    • install: 編譯完後,將 header, lib 安裝到指定目錄,預設目錄是:C:\Boost,大小約 2 G。
  5. 更多的客製化安裝,可以使用 bjam --help 查看 options。
    • bjam 是個有趣的東西,當我在 your_idr\boost_1_35_0\tools\jam\src\bin.ntx86 下執行 bjam --help 時,它跑出的訊息並不多,而切換到 your_idr\boost_1_35_0 時卻又是另一回事,它跑出豐富的 Boost 的編譯資訊,後來發現它會去讀取 Jamroot 這個檔案,這是格外要注意的一點。

Reference

  1. Boost.Build: http://www.boost.org/doc/libs/1_35_0/tools/build/v2/index.html
  2. Perforce Jam: http://www.perforce.com/jam/jam.html
  3. Install Boost: http://www.boost.org/doc/libs/1_35_0/doc/html/bbv2/installation.html
  4. Free Download on Boost Consulting: http://www.boost-consulting.com/products/free
  5. Boost Getting Started on Windows: http://www.boost.org/doc/libs/1_35_0/more/getting_started/windows.html
  6. Boost 提供的 bjam binary 下載點(包含許多種平台): http://tinyurl.com/2q36f
  7. Boost Source on Sourceforge: http://tinyurl.com/m7jqo

沒有留言:

Windows + Visual Studio + VSCode + CMake 的疑難雜症

Environment Windows 10 Visual Studio 2019 CMake 3.27.7 VSCode VSCode CMake Tools 1. CMAKE_BUILD_TYPE 是空的 參考一下 這篇 的處理。 大致上因為 Visual...