操做系統:Mac OS X Lion 10.7.4(11E53)
編程工具:Xcode 4.4.1(1448),並裝好了它的「Command Line Tools」。php
安裝過程可參考這些帖子——
在virtualbox上安裝Mac OS X Lion 之 配置過程
http://www.crifan.com/install_mac_os_x_lion_on_virtualbox_config_process/html
給VirtualBox上的Mac Lion安裝Xcode
http://www.crifan.com/install_xcode_for_mac_on_virtualbox/git
Mac OS X Lion下找不到GCC
http://blog.csdn.net/qinjienj/article/details/7456193github
對於mac系統,官網上主要是如下這幾個頁面——
Download for Mac OS X
http://www.gtk.org/download/macos.phpshell
Building GTK-OSX
https://live.gnome.org/GTK%2B/OSX/Buildingmacos
Bundling
https://live.gnome.org/GTK%2B/OSX/Bundling編程
我按照上述說明裝好了jhbuild和gtk-mac-bundler,但後面的就沒看懂,不知道怎麼裝。
在網上搜索了好久,找不到該方法的安裝經驗文章。遂放棄。xcode
在網上搜索了一下,發現有人推薦用homebrew安裝gtk(http://www.haskell.org/haskellwiki/Gtk2Hs/Mac)。因而決定試試。ruby
homebrew的官網是 http://mxcl.github.com/homebrew/。官網上介紹了homebrew的安裝方法,就是在終端上運行下面這條命令——bash
ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
該命令是ruby腳本。mac下不須要安裝ruby解釋環境,由於系統自帶了。
安裝好後,可使用下列命令來檢查homebrew版本,確認是否安裝成功——
brew –v
先檢查一下homebrew是否支持GTK+,在終端中輸入「brew search gtk」,執行結果以下——
macmatoiMac:~ mac$ brew search gtk gtk+ gtk-doc gtkglextmm gtkwave pygtkglext gtk+3 gtk-gnutella gtkmm lablgtk gtk-chtheme gtkglext gtksourceview pygtk
發現列表中有「gtk+」。因而在終端中輸入「brew install gtk+」進行安裝——
macmatoiMac:~ mac$ brew install gtk+ ==> Installing gtk+ dependency: pkg-config==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/pkg-config-
等了好久,發現仍是停在這一行。估計是由於SourceForge被牆了。放棄吧,按Ctrl+C終止。
又在網絡中搜索了好久,發現有人推薦fink(http://blog.sina.com.cn/s/blog_465881ff0100lnjq.html)。因而我決定試試。
fink的官網是 www.finkproject.org。
點擊國旗切換到中文,點擊「下載」連接轉到下載頁面。
由於OS X Lion是基於Intel處理器的,因而點擊「Fink 0.9.0 二進制安裝包 (Intel)」,下載「Fink-0.9.0-Intel-Installer.dmg」。
下載完成後,根據官網說明進行安裝——
2.雙擊 "Fink-0.9.0-Installer.dmg" 文件裝載磁盤映象,而後雙擊裏面 "Fink 0.9.0 Installer.pkg" 程序。接着按照屏幕的提示進行操做。 3.在安裝的最後階段,會打開一個終端程序,pathsetup.command 腳本會被自動運行。在編輯你的 shell 配置文件前,會提示請求你的贊成。當腳本運行完畢,關閉終端窗口之後,一切都安裝就緒了! 4.若是在此過程當中發生了什麼錯誤,你能夠嘗試從新運行一次安裝程序宗卷裏面的 pathsetup.command 文件(須要在終端窗口裏面運行)。 open /sw/bin/pathsetup.command (這個過程應該對你機器的每一個賬號都運行一次:每一個用戶應該登陸到本身的賬號運行一次 pathsetup.command 腳本)。 若是 pathsetup.command 產生了錯誤信息,請參考文檔,尤爲是《用戶指南》裏面的 2.3 「設置你的環境」。
但是在個人電腦上,在Pacifist上點擊安裝後,進度條跑完後並無出現終端窗口。
因而我按照說明,打開終端,輸入命令,結果報錯——
macmatoiMac:~ mac$ open /sw/bin/pathsetup.command The file /sw/bin/pathsetup.command does not exist.
找不到文件?將官網網頁切換到英語,發現命令是「/sw/bin/pathsetup.sh」。原來是中文版沒有更新。
因而在終端中輸入該命令運行腳本。
腳本運行完以後。依照官網說明在終端中輸入命令,結果報錯——
macmatoiMac:bin mac$ fink scanpackages; fink index-bash: fink: command not found
關閉終端,再打開終端運行命令,仍是報告「fink: command not found」。
關機,重啓。打開終端運行命令,這回OK了——
macmatoiMac:~ mac$ fink scanpackages; fink index UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27Password: UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27Updating the list of locally available binary packages. Scanning dists/local/main/binary-darwin-i386 Scanning dists/stable/main/binary-darwin-i386 Scanning dists/stable/crypto/binary-darwin-i386 Downloading the indexes of available packages in the binary distribution./sw/bin/apt-get-lockwait -q update Hit http://bindist.finkmirrors.net 10.5/release/main PackagesHit http://bindist.finkmirrors.net 10.5/release/main ReleaseHit http://bindist.finkmirrors.net 10.5/release/crypto PackagesHit http://bindist.finkmirrors.net 10.5/release/crypto ReleaseGet:1 http://bindist.finkmirrors.net 10.5/current/main Packages [2261B]Hit http://bindist.finkmirrors.net 10.5/current/main ReleaseGet:2 http://bindist.finkmirrors.net 10.5/current/crypto Packages [20B]Hit http://bindist.finkmirrors.net 10.5/current/crypto ReleaseFetched 2281B in 4s (484B/s) could not determine XFree86 version number Reading Package Lists... Building Dependency Tree... UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27Failed: It appears that Fink's package database is corrupted. Please run 'fink index -f' to recreate it.macmatoiMac:~ mac$ fink index UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27Failed: It appears that Fink's package database is corrupted. Please run 'fink index -f' to recreate it.macmatoiMac:~ mac$ fink index -f UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27Scanning package description files.......... macmatoiMac:~ mac$ fink index UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27Scanning package description files.......... macmatoiMac:~ mac$
中途「fink index」報錯,根據提示執行「fink index -f」。
先查一查是否有gtk——
macmatoiMac:bin mac$ fink list gtk*UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27Scanning package description files.......... could not determine XFree86 version number Information about 2545 packages read in 1 seconds. gtk+ 1.2.10-51 The Gimp Toolkit gtk+-data 1.2.10-51 The Gimp Toolkit gtk+-shlibs 1.2.10-51 The Gimp Toolkit gtk+2 2.6.10-1003 The Gimp Toolkit gtk+2-dev 2.6.10-1003 The Gimp Toolkit gtk+2-shlibs 2.6.10-1003 The Gimp Toolkit gtk-doc 1.3-1012 GTK+ - API documentation generator gtk-engines 0.12-3 Theme plugins for Gtk gtk2-engines 2.6.10-2 Theme plugins for Gtk gtkglarea 1.2.3-15 OpenGL widget for GTK+ gtkglarea2 1.99.0-1004 OpenGL widget for GTK+ gtkglarea2-s... 1.99.0-1004 OpenGL widget for GTK+ gtkglext1 1.0.6-1002 OpenGL Extension to GTK gtkglext1-sh... 1.0.6-1002 OpenGL Extension to GTK gtkgraph 0.6.2-4 Graphing calculator using Gtk+ gtkhtml 1.0.2-1054 HTML rendering/printing/editing engine gtkhtml-dev 1.0.2-1054 HTML rendering/printing/editing engine gtkhtml-shlibs 1.0.2-1054 HTML rendering/printing/editing engine gtkhtml1.1 1.1.7-1014 HTML rendering/printing/editing engine gtkhtml1.1-dev 1.1.7-1014 HTML rendering/printing/editing engine gtkhtml1.1-s... 1.1.7-1014 HTML rendering/printing/editing engine gtkmm2 2.2.12-1002 C++ interface for the gtk+2 library gtkmm2-dev 2.2.12-1002 C++ interface for the gtk+2 library gtkmm2-shlibs 2.2.12-1002 C++ interface for the gtk+2 library gtksourceview 1.0.1-1007 Source code viewing tool gtksourcevie... 1.0.1-1007 Headers and libraries for developing with... gtksourcevie... 1.0.1-1007 Shared libraries for gtksourceview gtkspell2 2.0.4-1005 Highlight misspelled words as you type gtkspell2-dev 2.0.4-1005 Highlight misspelled words as you type gtkspell2-sh... 2.0.4-1005 Highlight misspelled words as you type
發現有「gtk+2」,因而開始安裝——
macmatoiMac:bin mac$ fink install gtk+2UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27Scanning package description files.......... could not determine XFree86 version number Information about 2545 packages read in 2 seconds. could not determine XFree86 version number fink needs help picking an alternative to satisfy a virtual dependency. The candidates: (1) system-xfree86-manual-install: Manually installed X11 components (2) system-xfree86: [virtual package representing Apple's install of X11]Pick one: [1] 1The following package will be installed or updated: gtk+2The following 10 additional packages will be installed: atk1-shlibs glib2-shlibs gtk+2-shlibs libjpeg-shlibs libpng3-shlibs libtiff-shlibs pango1-xft2 pango1-xft2-shlibs system-xfree86-manual-install xdg-base Do you want to continue? [Y/n] y/sw/bin/apt-get-lockwait -q --ignore-breakage --download-only install atk1-shlibs=1.12.4-2 glib2-shlibs=2.12.0-103 gtk+2=2.6.10-1003 gtk+2-shlibs=2.6.10-1003 libjpeg-shlibs=6b-17 libpng3-shlibs=1:1.2.29-1 libtiff-shlibs=3.8.2-1002 pango1-xft2=1.10.1-1003 pango1-xft2-shlibs=1.10.1-1003 xdg-base=0.6-2could not determine XFree86 version number Reading Package Lists... Building Dependency Tree... The following NEW packages will be installed: atk1-shlibs glib2-shlibs gtk+2 gtk+2-shlibs libjpeg-shlibs libpng3-shlibs libtiff-shlibs pango1-xft2 pango1-xft2-shlibs xdg-base 0 packages upgraded, 10 newly installed, 0 to remove and 2 not upgraded. Need to get 7211kB of archives. After unpacking 23.1MB will be used. Get:1 http://bindist.finkmirrors.net 10.5/release/main xdg-base 0.6-2 [1232B]Get:2 http://bindist.finkmirrors.net 10.5/release/main glib2-shlibs 2.12.0-103 [863kB]Get:3 http://bindist.finkmirrors.net 10.5/release/main atk1-shlibs 1.12.4-2 [231kB]Get:4 http://bindist.finkmirrors.net 10.5/release/main libjpeg-shlibs 6b-17 [75.3kB]Get:5 http://bindist.finkmirrors.net 10.5/release/main libpng3-shlibs 1:1.2.29-1 [156kB]Get:6 http://bindist.finkmirrors.net 10.5/release/main libtiff-shlibs 3.8.2-1002 [127kB]Get:7 http://bindist.finkmirrors.net 10.5/release/main pango1-xft2-shlibs 1.10.1-1003 [301kB]Get:8 http://bindist.finkmirrors.net 10.5/release/main gtk+2-shlibs 2.6.10-1003 [2158kB]Get:9 http://bindist.finkmirrors.net 10.5/release/main pango1-xft2 1.10.1-1003 [29.1kB]Get:10 http://bindist.finkmirrors.net 10.5/release/main gtk+2 2.6.10-1003 [3269kB]Fetched 7211kB in 39s (183kB/s) Download complete and in download only mode Reading buildlock packages.../sw/bin/dpkg-lockwait -i /sw/var/cache/apt/archives/libjpeg-shlibs_6b-17_darwin-i386.deb could not determine XFree86 version number Selecting previously deselected package libjpeg-shlibs. (Reading database ... 4102 files and directories currently installed.) Unpacking libjpeg-shlibs (from .../libjpeg-shlibs_6b-17_darwin-i386.deb) ... Setting up libjpeg-shlibs (6b-17) ... Reading buildlock packages.../sw/bin/dpkg-lockwait -i /sw/var/cache/apt/archives/libpng3-shlibs_1%3a1.2.29-1_darwin-i386.deb could not determine XFree86 version number Selecting previously deselected package libpng3-shlibs. (Reading database ... 4106 files and directories currently installed.) Unpacking libpng3-shlibs (from .../libpng3-shlibs_1%3a1.2.29-1_darwin-i386.deb) ... Setting up libpng3-shlibs (1.2.29-1) ... Reading buildlock packages.../sw/bin/dpkg-lockwait -i /sw/var/cache/apt/archives/libtiff-shlibs_3.8.2-1002_darwin-i386.deb could not determine XFree86 version number Selecting previously deselected package libtiff-shlibs. (Reading database ... 4114 files and directories currently installed.) Unpacking libtiff-shlibs (from .../libtiff-shlibs_3.8.2-1002_darwin-i386.deb) ... Setting up libtiff-shlibs (3.8.2-1002) ... Setting runtime build-lock... dpkg-deb -b /sw/src/fink.build/root-fink-buildlock-system-xfree86-manual-install-0-0 /sw/src/fink.build dpkg-deb: building package `fink-buildlock-system-xfree86-manual-install-0-0' in `/sw/src/fink.build/fink-buildlock-system-xfree86-manual-install-0-0_2012.09.10-17.54.39_darwin-i386.deb'. Installing build-lock package.../sw/bin/dpkg-lockwait -i /sw/src/fink.build/fink-buildlock-system-xfree86-manual-install-0-0_2012.09.10-17.54.39_darwin-i386.deb could not determine XFree86 version number Selecting previously deselected package fink-buildlock-system-xfree86-manual-install-0-0. (Reading database ... 4119 files and directories currently installed.) Unpacking fink-buildlock-system-xfree86-manual-install-0-0 (from .../fink-buildlock-system-xfree86-manual-install-0-0_2012.09.10-17.54.39_darwin-i386.deb) ... Setting up fink-buildlock-system-xfree86-manual-install-0-0 (2012.09.10-17.54.39) ... Use of uninitialized value $darwin_osx in numeric eq (==) at /sw/lib/perl5/Fink/Services.pm line 1404. Use of uninitialized value $darwin_osx in concatenation (.) or string at /sw/lib/perl5/Fink/Services.pm line 1404. Argument "10.7 does not match the expected value of . Please run `..." isn't numeric in exit at /sw/lib/perl5/Fink/Services.pm line 1404.Removing runtime build-lock... Removing build-lock package.../sw/bin/dpkg-lockwait -r fink-buildlock-system-xfree86-manual-install-0-0could not determine XFree86 version number (Reading database ... 4120 files and directories currently installed.) Removing fink-buildlock-system-xfree86-manual-install-0-0 ...
彷佛沒有裝好。因而再運行了幾回「fink install gtk+2」,結果仍是輸出相似信息。
觀察了一下輸出信息,彷佛問題是出在檢測不到XFree86版本——
could not determine XFree86 version number
在網上搜索了好久,嘗試了很多辦法,最後發現這個帖子的辦法有效——
Interaction issue between XQuartz-2.6.0 and fink on Leopard.
http://finkers.wordpress.com/2011/02/06/375/
其大意是——在超級權限下編輯「/sw/lib/perl5/Fink/VirtPackage.pm」,找到這一行(大概是1736行)——
if (open (XBIN, "$xdir/bin/$binary -version -iokit 2>\&1 |")) {
將該行改成——
if (open (XBIN, "$xdir/bin/$binary -version 2>\&1 |")) {
5.2 具體操做
用文本編輯器打開「/sw/lib/perl5/Fink/VirtPackage.pm」,搜索「iokit」,找到了那一行——
由於不是超級權限,不能保存。因而我在Finder中將「/sw/lib/perl5/Fink/VirtPackage.pm」複製到home目錄。
而後打開終端,運行chmod命令修改文件權限——
macmatoiMac:~ mac$ ls -l VirtPackage.pm-rw-r--r-- 1 mac staff 55588 6 27 2008 VirtPackage.pm macmatoiMac:~ mac$ chmod go+w VirtPackage.pm
在文本編輯器中打開home目錄下的VirtPackage.pm,刪除「-iokit」,並保存。
如今VirtPackage.pm文件已經改好了,用chmod命令將文件權限改回來,再用sudo執行cp命令複製文件——
macmatoiMac:~ mac$ chmod go-w VirtPackage.pm macmatoiMac:~ mac$ ls -l VirtPackage.pm-rw-r--r--@ 1 mac staff 55581 9 13 00:07 VirtPackage.pm macmatoiMac:~ mac$ sudo cp VirtPackage.pm /sw/lib/perl5/Fink Password: macmatoiMac:~ mac$
如今再運行「fink install gtk+2」,發現能成功裝上,但好像裝的是運行環境,而不是開發版。因而使用「fink list」命令檢索包列表,依次安裝了這些東西——
fink install gtk+2fink install gtk+2-dev fink install glib2-dev fink install pkgconfig
詳細操做過程——
操做過程
這時運行gtk-demo,發現能成功打開GTK的demo——
剛纔彷佛已經將pkgconfig裝好了,因而我執行幾條命令測試一下——
macmatoiMac:~ mac$ pkg-config --cflags --libs gl-I/usr/X11/include -L/usr/X11/lib -lGL macmatoiMac:~ mac$ pkg-config --cflags --libs gtk+-2.0Package pangoxft was not found in the pkg-config search path. Perhaps you should add the directory containing `pangoxft.pc'to the PKG_CONFIG_PATH environment variable Package 'pangoxft', required by 'GDK', not found
發現gl庫成功了,而gtk+-2.0庫失敗了。
最開始懷疑是$PKG_CONFIG_PATH路徑配置問題,但配置後仍是不行——
macmatoiMac:~ mac$ echo $PKG_CONFIG_PATH macmatoiMac:~ mac$ PKG_CONFIG_PATH=/sw/lib/pkgconfig:$PKG_CONFIG_PATH macmatoiMac:~ mac$ echo $PKG_CONFIG_PATH/sw/lib/pkgconfig: macmatoiMac:~ mac$ pkg-config --cflags --libs gtk+-2.0Package pangoxft was not found in the pkg-config search path. Perhaps you should add the directory containing `pangoxft.pc'to the PKG_CONFIG_PATH environment variable Package 'pangoxft', required by 'GDK', not found
因而懷疑是缺乏pangoxft,執行「fink list pangoxft*」。但找不到——
macmatoiMac:~ mac$ fink list pangoxft*UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27Information about 2548 packages read in 2 seconds. macmatoiMac:~
而後再查查gdk——
macmatoiMac:~ mac$ fink list gdk*UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27Information about 2548 packages read in 0 seconds. gdk-pixbuf 0.22.0-13 Image loading and manipulation library gdk-pixbuf-s... 0.22.0-13 Image loading and manipulation library
發現有gdk-pixbuf,因而執行命令「fink install gdk-pixbuf」進行安裝。
裝好gdk-pixbuf後,執行「pkg-config --cflags --libs gtk+-2.0」,結果仍是報錯——
macmatoiMac:~ mac$ pkg-config --cflags --libs gtk+-2.0Package pangoxft was not found in the pkg-config search path. Perhaps you should add the directory containing `pangoxft.pc'to the PKG_CONFIG_PATH environment variable Package 'pangoxft', required by 'GDK', not found
想起GTK+中有一個庫叫「pango」,是否是它呢——
macmatoiMac:~ mac$ fink list pango*UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27Information about 2548 packages read in 1 seconds. pango1 1.2.1-25 I18N text handling system convinience pac... pango1-dev 1.2.1-25 I18N text handling system convinience pac... pango1-shlibs 1.2.1-25 I18N text handling system convinience pac... i pango1-xft2 1.10.1-1003 GTK+ - i18n libs (for XFree86 >= 4.3) pango1-xft2-dev 1.10.1-1003 GTK+ - i18n text development headers and ... pango1-xft2-... 1.10.1-1103 GTK+ - i18n libs (for freetype >= 2.1.9) pango1-xft2-... 1.10.1-1103 GTK+ - i18n text development headers and ... pango1-xft2-... 1.10.1-1103 GTK+ - i18n text shared libraries (for fr... i pango1-xft2-... 1.10.1-1003 GTK+ - i18n text shared libraries (for XF...
發現有pango1,因而執行命令執行「fink install pango1-dev」進行安裝。
裝好pango1-dev後,執行「pkg-config --cflags --libs gtk+-2.0」,又有報錯,但內容不一樣——
macmatoiMac:~ mac$ pkg-config --cflags --libs gtk+-2.0Package atk was not found in the pkg-config search path. Perhaps you should add the directory containing `atk.pc'to the PKG_CONFIG_PATH environment variable Package 'atk', required by 'GTK+', not found
根據前面的經驗,查找atk,並安裝atk1——
macmatoiMac:~ mac$ fink list atk*UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27Information about 2548 packages read in 1 seconds. atk1 1.12.4-2 Accessability Toolkit i atk1-shlibs 1.12.4-2 Accessability Toolkit macmatoiMac:~ mac$ fink install atk1 ……
裝好atk1後,執行「pkg-config --cflags --libs gtk+-2.0」,終於正確輸出了——
macmatoiMac:~ mac$ pkg-config --cflags --libs gtk+-2.0-I/sw/include/glib-2.0 -I/sw/lib/glib-2.0/include -I/sw/include/pango-1.0 -I/usr/X11/include -I/usr/X11/include/freetype2 -I/sw/include/gtk-2.0 -I/sw/include/atk-1.0 -I/sw/lib/gtk-2.0/include -Wl,-framework,CoreServices,-framework,ApplicationServices -L/sw/lib -L/usr/X11/lib -L/usr/X11R6/lib -lgtk-x11-2.0 -lgdk-x11-2.0 -lXrandr -lXinerama -lXext -lXfixes -lXcursor -latk-1.0 -lgdk_pixbuf-2.0 -lpangoxft-1.0 -lXft -lXrender -lpangox-1.0 -lX11 -lpangoft2-1.0 -lfontconfig -lfreetype -lz -lpango-1.0 -lm -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl -liconv
寫一個GTK+的簡單的測試程序(testgtk.c),將它放在home目錄。代碼以下——
#include <gtk/gtk.h>int main (int argc, char *argv[]) { GtkWidget *window; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* quit*/ g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(gtk_main_quit),NULL); gtk_window_set_title(GTK_WINDOW(window),"Hello GTK+!"); gtk_widget_show(window); gtk_main (); return 0; }
在終端上執行「gcc testgtk.c -o testgtk `pkg-config --cflags --libs gtk+-2.0`」開始編譯,結果報錯——
macmatoiMac:~ mac$ gcc testgtk.c -o testgtk `pkg-config --cflags --libs gtk+-2.0`ld: warning: ignoring file /sw/lib/libgtk-x11-2.0.dylib, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /sw/lib/libgtk-x11-2.0.dylibld: warning: ignoring file /sw/lib/libgdk-x11-2.0.dylib, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /sw/lib/libgdk-x11-2.0.dylibld: warning: ignoring file /sw/lib/libatk-1.0.dylib, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /sw/lib/libatk-1.0.dylibld: warning: ignoring file /sw/lib/libgdk_pixbuf-2.0.dylib, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /sw/lib/libgdk_pixbuf-2.0.dylibld: warning: ignoring file /sw/lib/libpangoxft-1.0.dylib, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /sw/lib/libpangoxft-1.0.dylibld: warning: ignoring file /sw/lib/libpangox-1.0.dylib, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /sw/lib/libpangox-1.0.dylibld: warning: ignoring file /sw/lib/libpangoft2-1.0.dylib, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /sw/lib/libpangoft2-1.0.dylibld: warning: ignoring file /sw/lib/libpango-1.0.dylib, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /sw/lib/libpango-1.0.dylibld: warning: ignoring file /sw/lib/libgobject-2.0.dylib, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /sw/lib/libgobject-2.0.dylibld: warning: ignoring file /sw/lib/libgmodule-2.0.dylib, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /sw/lib/libgmodule-2.0.dylibld: warning: ignoring file /sw/lib/libintl.dylib, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /sw/lib/libintl.dylibld: warning: ignoring file /sw/lib/libiconv.dylib, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /sw/lib/libiconv.dylibld: warning: ignoring file /sw/lib/libglib-2.0.dylib, file was built for unsupported file format ( 0xce 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 0 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): /sw/lib/libglib-2.0.dylib Undefined symbols for architecture x86_64: "_g_signal_connect_data", referenced from: _main in ccysPCRa.o "_g_type_check_instance_cast", referenced from: _main in ccysPCRa.o "_gtk_init", referenced from: _main in ccysPCRa.o "_gtk_main", referenced from: _main in ccysPCRa.o "_gtk_main_quit", referenced from: _main in ccysPCRa.o "_gtk_widget_show", referenced from: _main in ccysPCRa.o "_gtk_window_get_type", referenced from: _main in ccysPCRa.o "_gtk_window_new", referenced from: _main in ccysPCRa.o "_gtk_window_set_title", referenced from: _main in ccysPCRa.old: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status
看到「x86_64」,想到OS X Lion是64位系統,而fink安裝的GTK+極可能是32位。
因而給gcc加上「-m32」參數,成功經過編譯,並能正常運行——
macmatoiMac:~ mac$ gcc -m32 testgtk.c -o testgtk `pkg-config --cflags --libs gtk+-2.0` macmatoiMac:~ mac$ file testgtk testgtk: Mach-O executable i386 macmatoiMac:~ mac$ ./testgtk
(完)