編譯 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

Pipl: People Search

簡介

http://pipl.com/

      蠻有趣的一個網站,它專門用來找人的資料!可以使用:First/Last Name, City, State, Country 當關鍵字。並產生以下的結果(以 Bjarne Stroustrup 為例):

  • Quick Facts:  被查詢者快速資料。如 B.S. 是 C++ 的設計者。
  • Contact Details: 一些詳細的個人資料,如地址、電話等…
  • Profiles & Directories: 對方的個人資料,例如 B.S. 是學術中人,所以會有一些 indexing 或資料庫的個人自傳,演員的話還會幫你連結到 imdb 。
  • Publications: 著作嘛!查 paper 時,也可以來用一下?!可以對應到 cholar.google.com 不知道 IEEE, ACM 等專業期刊之後會不會列入?!
  • Web Pages: 相關的個人網頁,如果對方有上 wiki 之類的百科,也會列出來。
  • More: 上述的每一個項目都可以透過 more 連結到 google ,將結果以 google search
    呈現。

技術

     這個網站跟一般搜尋引擎有什麼不同呢?根據它網頁的說法是,一般抓網頁機器 人都只能抓到 surface web (主要是靠超連結串起的網頁)[3]。而另外有些網頁是以 online database 等非超連結方式儲存內容,稱作 deep web ,想抓這類的資料,你的機器人要能跟 online database 互動,也就是這些 online database 可能會有 search engine,你的機器人要能跟它們 talk talk ,不過望頁倒是沒有提到:它們所謂的互動是暴力互動(如:使用人名搜尋後,在進行資料萃取、整理)呢?還是有使用到一 些人名特徵的問法(如:Bjarne Stroustrup, telepone)。而這網頁的搜尋有點慢, 猜測是因為它只是個 mashup 的服務,背後都是 yahoo people、google scholar、 ZabaSearch。

用途?

     有時候看 mailing list 時,都會看到一些不錯的回答,若想知道對方更詳細的資料就可以透過這個網站,或許以後大家當老闆了,面試別人前,也可以來 pipl 一下唷!

學術?

     The Deep Web: Surfacing Hidden Value [1] 這篇文章提到 deep web 的資料量是 surface web 的 500 倍多(而且可能更具價值?!還沒看完文章,所以不知道), wiki [2] 列出了一些有趣的研究,有興趣的人,可以朝這發展?!

Reference

  1. The Deep Web: Surfacing Hidden Value: http://www.press.umich.edu/jep/07-01/bergman.html
  2. Deep Web - Widipedia: http://en.wikipedia.org/wiki/Deep_web
  3. Surface Web -Wikipedia: http://en.wikipedia.org/wiki/Surface_Web

Single/Double/Multiple Dispatch - Part 1

Design PatternGenerative ProgrammingModern C   Design Cover

     GoF 的 Design Patterns [1] 一書在 Visitor pattern 的實做描述中提到了 single/double dispatch,並針對 single dispatch 給了這樣的說明:

In single-dispatch languages, two criteria determine which operation will fulfill a request: the name of the request and the type of receiver

     若要快速地瞭解這句話,我們不妨白話點:函式的喚起是倚賴 function overriding (dynamic polymorphism) 與 overloading (static polymorphism) 的合作而完成的。以 C++ 為例,假設我們有以下的繼承架構:

hierarchy

當我們寫下這段程式碼時:

Base* ptr = new Derived1;
ptr->foo( 1 );
會被喚起的函式是 Derived1::foo( int ),而非 Base::foo( int ) ,當然更不可能是 Derived2::foo( int ),這是 function overriding (dynamic polymorphism),以 C++ 說,因為當下物件 ptr 的 vtbl 指向的型別是 Derived1 而非 Base ,這也就是 GoF 書中提到的 type of receiver 的部份。至於為何是 Derived1::foo( int ) 而不是 Derived1::foo( string ),就是倚賴 function overloading ,相當於GoF 書中提到的 name of the request

     那什麼是 double dispatch 呢?耶,有 double ,那有沒有 triple 呢?quadruple 呢?…?答案是有,而且我們還習慣把它們合在一稱為 multiple dispatch ,在另一本 OO 聖經書籍 Generative Programming [2] 中提到:多型機制可分為兩大類:single dispatch 和 multiple dispatch (又稱 multimethods):

Single dispatch corresponds to the Smalltalk idea of sending a message to an object, where the appropriate method (i.e., message implementation) is selected based on the type of the reciever.

Single dispatch introduces asymmetry with respect to the arguments because the first argument is treated specially.

A dispatch mechanism that uniformly uses all argument types for selecting the method is referred to as multiple dispatch, or mutlimethods.

     從上面的解釋中我們不難體會:常見語言(如:C++, Java, C# )的動態多型呼叫是可轉換成對等的 C 語言,轉換的虛擬碼如:

// C++
Base* ptr = new Derived1;
ptr->foo( 1 );

// C
foo_in_c( ptr, 1 );
foo_in_c( Base* ptr, int i )
{
	if ( "Base" == ptr->type_info() )
		Base::foo_in_c( i );
	else if ( "Derived1" == ptr->type_info() )
		Derived1::foo_in_c( i );
	else
		Derived2::foo_in_c( i );
}

我們可以透過 this 得到 ptr 的記憶體位置,並傳給轉換後的 foo_in_c 去決定該喚起的是哪個 method ,這種將第一個參數特別挑出來檢驗的機制就稱作 single dispatch ,反之,若是今天 foo 有 N 個參數,函式的喚起得考慮 run-time 時,每個參數的實際型別,那就是 multiple dispatch 。

     Multiple dispatch 比起 single dispatch 更具有表達與描述威力,因為同一個時間點,它同時考慮了多個 物件的 run-time 型別。而目前只有少數語言有支援這個特色:如 CLOS 。其他語言則需要透過 extension 。[7] 羅列了一些這類的整理資料,

     針對 C++ ,除了找 extension 外,還可以在經典書籍 Modern C++ Design 的第十一章,看到 Andrei 的一些討論。另外,[9] 這篇 C++ Report 的文章也提出了一個解法,[10] 則針對上面兩個方法有所簡單討論, [9] 也是從這找到的。

Reference

  1. Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, 1998
  2. Generative Programming: Methods, Tools, and Applications by Krzysztof Czarnecki and Ulrich W. Eisenecker, Addison Wesley, 2000
  3. Generative Programming: http://www.generative-programming.org/
  4. Modern C++ Design: Generic Programming and Design Patterns Applied by Andrei Alexandrescu, Addison Wesley, 2001
  5. Dynamic Dispatch - wikipedia: http://en.wikipedia.org/wiki/Single_dispatch
  6. Double Dispatch - wikipedia: http://en.wikipedia.org/wiki/Double_dispatch
  7. Multiple Dispatch - wikipedia: http://en.wikipedia.org/wiki/Multiple_dispatch
  8. Single, Double and Multiple Dispatch: http://ifacethoughts.net/2006/07/29/single-double-and-multiple-dispatch/
  9. Multiple Dispatch A New Approach using templates and RTTI: http://www.eptacom.net/pubblicazioni/pub_eng/mdisp.html
  10. Re: 備份 : Multiple Dispatch: http://phpbb.godfat.org/viewtopic.php?t=204&highlight=&sid=0ffb75220260fea3aa497c8a17fe710b

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

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