HAYAGUI

MacOS X 10.4 + configureベースのオープンソースでUniversal Binary

はじめに

前回は、Xcode 2.2 で C言語の Hello Worldを作りましたが、 オープンソースでユニバーサルバイナリを作ってみます。

ハードウェアは、PPC の iBookG4 800MHz 。OSは、MacOSX 10.4.5 です。

オープンソースは、smtpclientです。

参考にしたWebは、Appleの http://developer.apple.com/jp/technotes/tn2005/tn2137.html です。

helloworld

前回 Xcode で作った hello world の main.c を gcc でコンパイルします。
Terminal を開いて、helloworld ディレクトリに cd して、こんな感じ。
ibg4:~/helloworld kenz$ gcc -arch i386 -arch ppc -arch ppc64 -isysroot /Developer/SDKs/MacOSX10.4u.sdk main.c 
ibg4:~/helloworld kenz$ file a.out a.out: Mach-O fat file with 3 architectures
a.out (for architecture i386):  Mach-O executable i386
a.out (for architecture ppc):   Mach-O executable ppc
a.out (for architecture ppc64): Mach-O 64-bit executable ppc64
ibg4:~/helloworld kenz$ 
参考にした Apple の Web にも書いていますが、intel Mac の場合は、-isysroot が必要ありません。 ppc環境で -isysroot を設定しないと、/usr/lib にある libSystem.B.dylib を使用されるため、エラーになります。ppc の /usr/lib/libSystem.B.dylib は、i386 に対応していません。
ibg4:/usr/lib kenz$ pwd             
/usr/lib
ibg4:/usr/lib kenz$ ls -la libSystem.B.dylib 
-r-xr-xr-x   1 root  wheel  4314524 Mar 15 09:26 libSystem.B.dylib
ibg4:/usr/lib kenz$ file libSystem.B.dylib 
libSystem.B.dylib: Mach-O fat file with 2 architectures
libSystem.B.dylib (for architecture ppc64):     Mach-O 64-bit dynamically linked shared library ppc64
libSystem.B.dylib (for architecture ppc):       Mach-O dynamically linked shared library ppc
ibg4:/usr/lib kenz$ 

smtpclient

configure を使用するオープンソースをコンパイルします。

smtpclient を ダウンロードして、tar zx します。

ibg4:~/smtpclient-1.0.0 kenz$ pwd
/Users/kenz/smtpclient-1.0.0
ibg4:~/smtpclient-1.0.0 kenz$ export CFLAGS="-arch i386 -arch ppc -arch ppc64 -isysroot /Developer/SDKs/MacOSX10.4u.sdk"
ibg4:~/smtpclient-1.0.0 kenz$ ./configure
ibg4:~/smtpclient-1.0.0 kenz$ make LDFLAGS="-arch i386 -arch ppc -arch ppc64 -isysroot /Developer/SDKs/MacOSX10.4u.sdk"
ibg4:~/smtpclient-1.0.0 kenz$ ls -la smtpclient
-rwxr-xr-x   1 kenz  kenz  109735 Apr  3 22:46 smtpclient
ibg4:~/smtpclient-1.0.0 kenz$ file smtpclient
smtpclient: Mach-O fat file with 3 architectures
smtpclient (for architecture i386):     Mach-O executable i386
smtpclient (for architecture ppc):      Mach-O executable ppc
smtpclient (for architecture ppc64):    Mach-O 64-bit executable ppc64
とこんな感じ。
素敵!
戻る



(C)1999 - 2006 Kenji Ito All rights reserved.