http://puredata.info/docs/developer/PdExternalsInXcode
http://musicgrad.ucsd.edu/~cbaker/Home/Code/Pd/
http://iem.at/pd/externals-HOWTO/
內文可能會有些疏失,因為自己對Xcode也還不熟,請大家多包含。
- 系統:OSX 10.8.3
- Xcode 版本:4.6.2
- Pd版本:Pd-extended 0.42.5
步驟一:打開Xcode,建立一個新的Project(Create a new Xcode project)
步驟二:在範本選擇裡,挑選OS X標籤下的 > Framework & Library > C/C++ Library
步驟三:建立專案的名稱,這裡命名為「HelloWorld」,下面的作者名稱可以填上自己的姓名。接著它會問你專案儲存入徑,我暫且把專案儲存在桌面上。
步驟四:建立完成後,會出現如下圖的顯示,並且還未進行任何的編譯動作,所以在產品那欄會出現紅字顯示,Products:libHelloWorld.dylib。
步驟五:建立一個新的檔案,Menu bar>File>New>File,並選擇C and C++標籤下的C File,並且取名為HelloWorld.ch。
步驟六:建立完成後,在HelloWorld 計劃下,會出現一個HelloWorld.c的檔案,並且HelloWorld.c會有預設的程式碼如下:
// // HelloWorld.c // HelloWorld // // Created by aluan on 13/5/6. // Copyright (c) 2013年 aluan. All rights reserved. // #include
#include "m_pd.h" static t_class *helloworld_class; typedef struct _helloworld { t_object x_obj; } t_helloworld; void helloworld_bang(t_helloworld *x) { post("Hello world !! You do a good job ");//放入你想要秀出的字串 } void *helloworld_new(void) { t_helloworld *x = (t_helloworld *)pd_new(helloworld_class); return (void *)x; } void helloworld_setup(void) { helloworld_class = class_new(gensym("helloworld"), (t_newmethod)helloworld_new, 0, sizeof(t_helloworld), CLASS_DEFAULT, 0); class_addbang(helloworld_class, helloworld_bang); }
步驟八:這時候Xcode應該會出現一個緊告標誌,告知你他找尋不到「m_pd.h」這個檔案,「m_pd.h」這標頭檔是由Miller所撰寫的,檔案包含Pd 內建的一些函數宣告,所以如果沒有這個檔案,就無法編譯擴充物件。所以必須透過User Header Search Paths指定路徑到「m_pd.h」這檔案。
「m_pd.h」這檔案在我電腦是放置在應用程式>Pd-extended.app裡面
(/Applications/Pd-extended.app/Contents/Resources/include/pdextended)
,所以你可以把這路徑加入其中,如下圖。
步驟八:接著還需要設計幾個屬性,才能開始編譯
- Set Deployment Location as checked
- Set Installation Build Products Location to /
- Set Installation Directory to (你的擴充物件放置處,或者之後再透過Pd 去 path此檔案也可以 )
- Set Other Linker Flags to -undefined dynamic_lookup
- Set Executable Prefix to be blank (設置為空白,不然產出的物件會帶lib的名稱)
- Set Product Name to helloworld
- Set Executable Extension to pd_darwin
版本選擇:32-bit intel
SDK:OS X 10.7
OS X Deployment Target:OS X 10.7
步驟九:按下Build 按鈕,如果在你剛剛指定的資料夾Installation Directory的地方,看到helloworld.pd_darwin 這個檔案,及代表編譯成功,
步驟十:重開Pd,建立物件[helloworld],並送[bang]的訊號進去,大功告成!!
步驟十:重開Pd,建立物件[helloworld],並送[bang]的訊號進去,大功告成!!