Universal Binary についてちょっと調べてみた
というのがあって,Universal Binary って何じゃろと思ったので,調べてみた.
- http://developer.apple.com/jp/macosx/adoptinguniversalbinaries.html
- http://macwiki.sourceforge.jp/wiki/index.php/UniversalBinary
どうやら,アーキテクチャ: PowerPC, Intell の等の複数のバイナリを含む実行可能ファイルを作る技術らしい.
Fat binary とも呼ぶ.と
例えば,
$ gcc-4.2 test.c $ file a.out a.out: Mach-O 64-bit executable x86_64 $ ./a.out Hello, world! $ arch -x86_64 ./a.out Hello, world! $ arch -i386 ./a.out arch: posix_spawnp: ./a.out: Bad CPU type in executable [1] 29225 exit 1 arch -i386 ./a.out $ gcc-4.2 -arch x86_64 -arch i386 test.c $ file a.out a.out: Mach-O universal binary with 2 architectures a.out (for architecture x86_64): Mach-O 64-bit executable x86_64 a.out (for architecture i386): Mach-O executable i386 $ ./a.out Hello, world! $ arch -i386 ./a.out Hello, world! $ arch -x86_64 ./a.out Hello, world!
- gcc -arch {i386,x86_64} 指定で,複数指定するとUniversal Binary になる.(コンパイルできれば)
- lipo でアーキテクチャごとのファイルを 1つに纏めることもできるよ
- arch -{i386,x86_64} 指定で,目的のアーキテクチャで実行できる.(ppc はRosetta が必要?)
MacPorts を使うなら,ここからまたPorts がそれ用に作られてるかを調べたりしないとなのかな?
$ file /opt/local/bin/perl5.10 /opt/local/bin/perl5.10: Mach-O 64-bit executable x86_64 $ port variants perl5.10 perl5.10 has the variants: darwin: Platform variant, selected automatically shared: Build shared perl library threads: Build with thread support
Snow Leopard はデフォルトで Universal=x86_64,i386 だったので,
default variants に追加しておいてみた.
$ egrep universal_archs /opt/local/etc/macports/macports.conf universal_archs x86_64 i386 $ egrep -v '^#' /opt/local/etc/macports/variants.conf +universal