作者:zyl910。
折騰了好幾天,終於在Mac OS X Lion 10.7.4上裝好GTK+了。其中走了不少彎路,於是將經驗教訓總結了一下。
一、系統環境(OS X與XCode)
操作系統:Mac OS X Lion 10.7.4(11E53)
編程工具:Xcode 4.4.1(1448),並裝好了它的“Command Line Tools”。
安裝過程可參考這些帖子——
在virtualbox上安裝Mac OS X Lion 之 配置過程
http://www.crifan.com/install_mac_os_x_lion_on_virtualbox_config_process/
給VirtualBox上的Mac Lion安裝Xcode
http://www.crifan.com/install_xcode_for_mac_on_virtualbox/
Mac OS X Lion下找不到GCC
http://blog.csdn.net/qinjienj/article/details/7456193
二、嘗試GTK+官網方法
對於mac系統,官網上主要是以下這幾個頁面——
Download for Mac OS X
http://www.gtk.org/download/macos.php
Building GTK-OSX
https://live.gnome.org/GTK%2B/OSX/Building
Bundling
https://live.gnome.org/GTK%2B/OSX/Bundling
我按照上述說明裝好了jhbuild和gtk-mac-bundler,但后面的就沒看懂,不知道怎么裝。
在網上搜索了很久,找不到該方法的安裝經驗文章。遂放棄。
三、嘗試利用homebrew安裝
在網上搜索了一下,發現有人推薦用homebrew安裝gtk(http://www.haskell.org/haskellwiki/Gtk2Hs/Mac)。於是決定試試。
3.1 安裝homebrew
homebrew的官網是 http://mxcl.github.com/homebrew/。官網上介紹了homebrew的安裝方法,就是在終端上運行下面這條命令——
ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
該命令是ruby腳本。mac下不需要安裝ruby解釋環境,因為系統自帶了。
安裝好后,可以使用下列命令來檢查homebrew版本,確認是否安裝成功——
brew –v
3.2 嘗試安裝GTK+
先檢查一下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安裝
又在網絡中搜索了很久,發現有人推薦fink(http://blog.sina.com.cn/s/blog_465881ff0100lnjq.html)。於是我決定試試。
4.1 安裝fink
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 27 Password: UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Updating 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 Packages Hit http://bindist.finkmirrors.net 10.5/release/main Release Hit http://bindist.finkmirrors.net 10.5/release/crypto Packages Hit http://bindist.finkmirrors.net 10.5/release/crypto Release Get:1 http://bindist.finkmirrors.net 10.5/current/main Packages [2261B] Hit http://bindist.finkmirrors.net 10.5/current/main Release Get:2 http://bindist.finkmirrors.net 10.5/current/crypto Packages [20B] Hit http://bindist.finkmirrors.net 10.5/current/crypto Release Fetched 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 27 UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Failed: 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 27 UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Failed: 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 27 UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Scanning 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 27 UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Scanning package description files.......... macmatoiMac:~ mac$
中途“fink index”報錯,根據提示執行“fink index -f”。
4.2 嘗試安裝GTK+,遇到問題
先查一查是否有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 27 Scanning 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+2 UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Scanning 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] 1 The following package will be installed or updated: gtk+2 The 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-2 could 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-0 could 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
五、解決fink的“could not determine XFree86 version number”錯誤
5.1 解決辦法
在網上搜索了很久,嘗試了不少辦法,最后發現這個帖子的辦法有效——
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$

六、裝好GTK+2,並編譯程序
6.1 直到能運行gtk-demo
現在再運行“fink install gtk+2”,發現能成功裝上,但好像裝的是運行環境,而不是開發版。於是使用“fink list”命令檢索包列表,依次安裝了這些東西——
fink install gtk+2 fink install gtk+2-dev fink install glib2-dev fink install pkgconfig
詳細操作過程——
操作過程
macmatoiMac:~ mac$ fink install gtk+2 UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Information about 2548 packages read in 2 seconds. The following package will be installed or updated: gtk+2 The following 6 additional packages will be installed: atk1-shlibs glib2-shlibs gtk+2-shlibs pango1-xft2 pango1-xft2-shlibs xdg-base Do you want to continue? [Y/n] Y Reading buildlock packages... /sw/bin/dpkg-lockwait -i /sw/var/cache/apt/archives/xdg-base_0.6-2_darwin-i386.deb Selecting previously deselected package xdg-base. (Reading database ... 4119 files and directories currently installed.) Unpacking xdg-base (from .../xdg-base_0.6-2_darwin-i386.deb) ... Setting up xdg-base (0.6-2) ... Reading buildlock packages... /sw/bin/dpkg-lockwait -i /sw/var/cache/apt/archives/glib2-shlibs_2.12.0-103_darwin-i386.deb Selecting previously deselected package glib2-shlibs. (Reading database ... 4121 files and directories currently installed.) Unpacking glib2-shlibs (from .../glib2-shlibs_2.12.0-103_darwin-i386.deb) ... Setting up glib2-shlibs (2.12.0-103) ... Reading buildlock packages... /sw/bin/dpkg-lockwait -i /sw/var/cache/apt/archives/pango1-xft2_1.10.1-1003_darwin-i386.deb /sw/var/cache/apt/archives/pango1-xft2-shlibs_1.10.1-1003_darwin-i386.deb Selecting previously deselected package pango1-xft2. (Reading database ... 4299 files and directories currently installed.) Unpacking pango1-xft2 (from .../pango1-xft2_1.10.1-1003_darwin-i386.deb) ... Selecting previously deselected package pango1-xft2-shlibs. Unpacking pango1-xft2-shlibs (from .../pango1-xft2-shlibs_1.10.1-1003_darwin-i386.deb) ... Setting up pango1-xft2-shlibs (1.10.1-1003) ... Setting up pango1-xft2 (1.10.1-1003) ... Reading buildlock packages... /sw/bin/dpkg-lockwait -i /sw/var/cache/apt/archives/atk1-shlibs_1.12.4-2_darwin-i386.deb Selecting previously deselected package atk1-shlibs. (Reading database ... 4359 files and directories currently installed.) Unpacking atk1-shlibs (from .../atk1-shlibs_1.12.4-2_darwin-i386.deb) ... Setting up atk1-shlibs (1.12.4-2) ... Reading buildlock packages... /sw/bin/dpkg-lockwait -i /sw/var/cache/apt/archives/gtk+2_2.6.10-1003_darwin-i386.deb /sw/var/cache/apt/archives/gtk+2-shlibs_2.6.10-1003_darwin-i386.deb Selecting previously deselected package gtk+2. (Reading database ... 4469 files and directories currently installed.) Unpacking gtk+2 (from .../gtk+2_2.6.10-1003_darwin-i386.deb) ... Selecting previously deselected package gtk+2-shlibs. Unpacking gtk+2-shlibs (from .../gtk+2-shlibs_2.6.10-1003_darwin-i386.deb) ... Setting up gtk+2-shlibs (2.6.10-1003) ... Setting up gtk+2 (2.6.10-1003) ... macmatoiMac:~ mac$ fink list gtk+ UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Information about 2548 packages read in 2 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 i gtk+2 2.6.10-1003 The Gimp Toolkit gtk+2-dev 2.6.10-1003 The Gimp Toolkit i gtk+2-shlibs 2.6.10-1003 The Gimp Toolkit macmatoiMac:~ mac$ fink install gtk+2dev UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Information about 2548 packages read in 0 seconds. Failed: no package found for specification 'gtk+2dev'! macmatoiMac:~ mac$ fink install gtk+2-dev UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Information about 2548 packages read in 1 seconds. The following package will be installed or updated: gtk+2-dev /sw/bin/apt-get-lockwait -q --ignore-breakage --download-only install gtk+2-dev=2.6.10-1003 Reading Package Lists... Building Dependency Tree... The following NEW packages will be installed: gtk+2-dev 0 packages upgraded, 1 newly installed, 0 to remove and 2 not upgraded. Need to get 4773kB of archives. After unpacking 22.5MB will be used. Get:1 http://bindist.finkmirrors.net 10.5/release/main gtk+2-dev 2.6.10-1003 [4773kB] Fetched 4773kB in 20s (231kB/s) Download complete and in download only mode Reading buildlock packages... /sw/bin/dpkg-lockwait -i /sw/var/cache/apt/archives/gtk+2-dev_2.6.10-1003_darwin-i386.deb Selecting previously deselected package gtk+2-dev. (Reading database ... 4769 files and directories currently installed.) Unpacking gtk+2-dev (from .../gtk+2-dev_2.6.10-1003_darwin-i386.deb) ... Setting up gtk+2-dev (2.6.10-1003) ... macmatoiMac:~ mac$ fink list gtk+ UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Information about 2548 packages read in 0 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 i gtk+2 2.6.10-1003 The Gimp Toolkit i gtk+2-dev 2.6.10-1003 The Gimp Toolkit i gtk+2-shlibs 2.6.10-1003 The Gimp Toolkit macmatoiMac:~ mac$ fink list pkg-config UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Information about 2548 packages read in 1 seconds. macmatoiMac:~ mac$ fink list pkg-config* UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Information about 2548 packages read in 0 seconds. macmatoiMac:~ mac$ fink list pkgconfig* UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Information about 2548 packages read in 1 seconds. pkgconfig 0.21-1 Manager for library compile/link flags macmatoiMac:~ mac$ fink list glib* UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Information about 2548 packages read in 1 seconds. glib 1.2.10-50 Common C routines used by Gtk+ and other ... glib-shlibs 1.2.10-50 Common C routines used by Gtk+ and other ... glib2 2.12.0-103 Handy library of utility functions glib2-dev 2.12.0-103 Handy library of utility functions i glib2-shlibs 2.12.0-103 Handy library of utility functions glibwww 0.2-14 Set of register/unregister functions glibwww-shlibs 0.2-14 Set of register/unregister functions macmatoiMac:~ mac$ fink install glib2-dev UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Password: UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Information about 2548 packages read in 0 seconds. The following package will be installed or updated: glib2-dev /sw/bin/apt-get-lockwait -q --ignore-breakage --download-only install glib2-dev=2.12.0-103 Reading Package Lists... Building Dependency Tree... The following NEW packages will be installed: glib2-dev 0 packages upgraded, 1 newly installed, 0 to remove and 2 not upgraded. Need to get 1540kB of archives. After unpacking 9032kB will be used. Get:1 http://bindist.finkmirrors.net 10.5/release/main glib2-dev 2.12.0-103 [1540kB] Fetched 1540kB in 7s (209kB/s) Download complete and in download only mode Reading buildlock packages... /sw/bin/dpkg-lockwait -i /sw/var/cache/apt/archives/glib2-dev_2.12.0-103_darwin-i386.deb Selecting previously deselected package glib2-dev. (Reading database ... 5592 files and directories currently installed.) Unpacking glib2-dev (from .../glib2-dev_2.12.0-103_darwin-i386.deb) ... Setting up glib2-dev (2.12.0-103) ... macmatoiMac:~ mac$ fink install pkgconfig UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 UNIVERSAL->import is deprecated and will be removed in a future perl at /sw/lib/perl5/Fink/Checksum.pm line 27 Information about 2548 packages read in 1 seconds. The following package will be installed or updated: pkgconfig The following additional package will be installed: glib-shlibs Do you want to continue? [Y/n] Y /sw/bin/apt-get-lockwait -q --ignore-breakage --download-only install glib-shlibs=1.2.10-50 pkgconfig=0.21-1 Reading Package Lists... Building Dependency Tree... The following NEW packages will be installed: glib-shlibs pkgconfig 0 packages upgraded, 2 newly installed, 0 to remove and 2 not upgraded. Need to get 158kB of archives. After unpacking 479kB will be used. Get:1 http://bindist.finkmirrors.net 10.5/release/main glib-shlibs 1.2.10-50 [98.7kB] Get:2 http://bindist.finkmirrors.net 10.5/release/main pkgconfig 0.21-1 [58.9kB] Fetched 158kB in 3s (46.5kB/s) Download complete and in download only mode Reading buildlock packages... /sw/bin/dpkg-lockwait -i /sw/var/cache/apt/archives/glib-shlibs_1.2.10-50_darwin-i386.deb Selecting previously deselected package glib-shlibs. (Reading database ... 5887 files and directories currently installed.) Unpacking glib-shlibs (from .../glib-shlibs_1.2.10-50_darwin-i386.deb) ... Setting up glib-shlibs (1.2.10-50) ... Reading buildlock packages... /sw/bin/dpkg-lockwait -i /sw/var/cache/apt/archives/pkgconfig_0.21-1_darwin-i386.deb Selecting previously deselected package pkgconfig. (Reading database ... 5898 files and directories currently installed.) Unpacking pkgconfig (from .../pkgconfig_0.21-1_darwin-i386.deb) ... Setting up pkgconfig (0.21-1) ... macmatoiMac:~ mac$ gtk-demo
這時運行gtk-demo,發現能成功打開GTK的demo——

6.2 直到能運行pkg-config --cflags --libs gtk+-2.0
剛才似乎已經將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.0 Package 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.0 Package 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 27 Information 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 27 Information 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.0 Package 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 27 Information 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.0 Package 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 27 Information 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
6.3 編譯GTK+程序
寫一個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.dylib ld: 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.dylib ld: 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.dylib ld: 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.dylib ld: 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.dylib ld: 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.dylib ld: 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.dylib ld: 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.dylib ld: 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.dylib ld: 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.dylib ld: 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.dylib ld: 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.dylib ld: 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.o ld: 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

(完)
