macports在Leopard下编译universal的一个问题

转载自水木jjgod的blog
http://blog.jjgod.org/2007/12/03/macports-leopard-universal-issue/ 

December 3rd, 2007 by jjgod

近来在开发一个小软件,需要分发程序链接了一些用 macports 安装的库,众所周知,用 macports 安装 universal binary 程序是通过 +universal 这个缺省 variant 实现的。在默认情况下,显然用户不愿意安装 universal 的,既然都在自己机器上编译了,去编译其他平台的二进制程序即浪费时间又浪费空间。所以默认这个 variant 是禁用的,可是如果你自己开发的 Universal Binary 应用要链接用 macports 安装的那些库时,就必须首先确保这些库是 universal binary。

可是在 10.5 下通过 +universal 之后,链接程序会遇到类似下面的错误:

$ sudo port install gettext +universal

—>  Building gettext with target all
Error: Target org.macports.build returned: … returned error 2

gcc -dynamiclib  -o … -L/opt/local/lib -lc 
-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386
-arch ppc -arch i386 -arch ppc -Wl,-framework -Wl,CoreFoundation
-install_name  /opt/local/lib/libintl.8.dylib
-compatibility_version 9 -current_version 9.2
ld: library not found for -ldylib1.10.5.o
collect2: ld returned 1 exit status

这是什么原因呢?仔细看最关键的地方在于,macports 缺省使用了 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc 这个编译器参数来生成,可是在 Mac OS X 10.5 下,如果仅仅使用这个参数,系统仍然会以为你要编译的是 10.5 下运行的程序,所以最后会尝试链接 10.5 的 libc,问题是 10.5 的 libc 在 10.4 的 SDK 路径下当然找不到,于是就出错了。参考 Xcode-Users 上的讨论(http://lists.apple.com/archives/Xcode-users/2007/Oct/msg00686.html)。

怎么解决呢?也简单,加上 -mmacosx-version-min=10.4 这个编译参数就行了。不过对于 macports 来说,在哪儿加倒是一个问题,你可以针对每个 port,在 Portfile 里加上:

configure.universal_cflags-append  "-mmacosx-version-min=10.4"

也可以一劳永逸地通过修改 /opt/local/share/macports/Tcl/port1.0/portconfigure.tcl 脚本中的 default configure.universal_cflags 实现,这里是一个简单的 patch(http://trac.macosforge.org/projects/macports/attachment/ticket/13475/portconfigure.t cl.diff)。

这个 patch 已经发到了 macports 的 trac 上,希望能尽快在官方版本中得到修复。

/*
这个问题上次我试图编译aMule CVS Universal Binary的时候就发现了,呵呵。这次要把常用的开发工具全部搞成Universal Binary的。其实Universal Binary这个东东就和Classical一样,总是对一半人有用,一半人没用,但是对于开发者就比较痛苦了。要么准备两套开发平台,要么从头开始把各种libs和tools全部搞成Universal Binary。在x86平台上编译PowerPC构架部分真是慢。。。。

Author: armadillo

傻傻的笨蛋,什么都不懂的Small Kids,总是在幻想,轻轻地走来,静静地站在那里,默默地看着一切,细细地思考,然后悄悄地离开……永远都不愿意留在这里……You mustn't allow yourself to be chained to fate, to be ruled by your genes. Human beings can choose the kind of life that they want to live. What's important is that you choose life... and then live.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.