如何在Lion下的Xcode 4.2中添加PPC / PPC64支持?

时间:2011-08-21 09:37:12

标签: xcode macos gcc osx-lion powerpc

我有一个Lion(10.7.1)系统,我在其上安装了Xcode 4.2。假设我有一个简单的C程序helloWorld.c,如下所示:

#include <stdio.h>
main() {
  printf("hello, world\n");
}

使用此设置,我想尝试编译helloWorld.c以用于PPC和PPC64体系结构,例如

$ gcc -arch ppc helloWorld.c -o helloWorld

这会出现以下错误消息:

llvm-gcc-4.2: error trying to exec '/usr/bin/../llvm-gcc-4.2/bin/powerpc-apple-darwin11-llvm-gcc-4.2': execvp: No such file or directory

如何将PowerPC的支持恢复到我的Xcode 4安装?

我已尝试过this previous Stack Overflow post中列出的说明,但这些说明不适用于我的Lion安装。

我正在使用Xcode 3.2.6 installer located on Apple's dev site

从符号链接中,我怀疑这些说明适用于10.6安装,但不适用于10.7。

在任何情况下,Xcode 3.2.6安装中的某些源文件和目录不存在,无法从Xcode 3安装中的其他位置创建符号链接。 (例如,没有/Xcode3/usr/bin目录可以从中链接as二进制文件。)

有没有人幸运从Lion系统编译PPC和PPC64二进制文件?

要获得赏金,请写一个相当详细的答案。对于我自己,也为后人。 :)

编辑 - 2011年8月31日

所以我尝试了Laurent指出并进一步改进的修改,但这还不足以让PPC支持工作。

我添加了符号链接,试图帮助gcc找到所需的资源:

$ sudo ln -s /Xcode3/usr/llvm-gcc-4.2/bin/powerpc-apple-darwin10-llvm-gcc-4.2 /usr/llvm-gcc-4.2/bin/powerpc-apple-darwin10-llvm-gcc-4.2 
$ sudo ln -s /Xcode3/usr/llvm-gcc-4.2/bin/powerpc-apple-darwin10-llvm-g++-4.2 /usr/llvm-gcc-4.2/bin/powerpc-apple-darwin10-llvm-g++-4.2
$ sudo ln -s /Xcode3/usr/llvm-gcc-4.2/bin/powerpc-apple-darwin10-llvm-gcc-4.2 /usr/llvm-gcc-4.2/bin/powerpc-apple-darwin11-llvm-gcc-4.2 
$ sudo ln -s /Xcode3/usr/llvm-gcc-4.2/bin/powerpc-apple-darwin10-llvm-g++-4.2 /usr/llvm-gcc-4.2/bin/powerpc-apple-darwin11-llvm-g++-4.2

当我尝试编译我的测试应用程序时,我遇到了很多错误:

$ gcc -arch ppc helloWorld.c -o helloWorld
powerpc-apple-darwin11-llvm-gcc-4.2: 2: No such file or directory
In file included from /usr/include/stdio.h:64,
                 from helloWorld.c:1:
/usr/include/sys/cdefs.h:540:4: error: #error Unknown architecture
In file included from /usr/include/sys/_types.h:33,
                 from /usr/include/_types.h:27,
                 from /usr/include/stdio.h:67,
                 from helloWorld.c:1:
/usr/include/machine/_types.h:36:2: error: #error architecture not supported
In file included from /usr/include/_types.h:27,
                 from /usr/include/stdio.h:67,
                 from helloWorld.c:1:
/usr/include/sys/_types.h:94: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_blkcnt_t’
/usr/include/sys/_types.h:95: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_blksize_t’
/usr/include/sys/_types.h:96: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_dev_t’
/usr/include/sys/_types.h:99: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_gid_t’
/usr/include/sys/_types.h:100: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_id_t’
/usr/include/sys/_types.h:101: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_ino64_t’
/usr/include/sys/_types.h:103: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_ino_t’
/usr/include/sys/_types.h:107: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_mach_port_name_t’
/usr/include/sys/_types.h:108: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_mach_port_t’
/usr/include/sys/_types.h:109: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_mode_t’
/usr/include/sys/_types.h:110: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_off_t’
/usr/include/sys/_types.h:111: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_pid_t’
/usr/include/sys/_types.h:131: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_sigset_t’
/usr/include/sys/_types.h:132: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_suseconds_t’
/usr/include/sys/_types.h:133: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_uid_t’
/usr/include/sys/_types.h:134: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__darwin_useconds_t’
...
/usr/include/secure/_stdio.h:62: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__DARWIN_LDBL_COMPAT’
/usr/include/secure/_stdio.h:67: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/secure/_stdio.h:67: error: expected declaration specifiers or ‘...’ before ‘size_t’
/usr/include/secure/_stdio.h:68: error: expected declaration specifiers or ‘...’ before ‘va_list’
/usr/include/secure/_stdio.h:69: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__DARWIN_LDBL_COMPAT’
helloWorld.c:3: error: expected declaration specifiers before ‘main’
helloWorld.c:5: error: old-style parameter declarations in prototyped function definition
/usr/include/stdio.h:252: error: parameter name omitted
/usr/include/stdio.h:252: error: parameter name omitted
helloWorld.c:5: error: expected ‘{’ at end of input

也许我应该添加的编译选项指向Xcode3标题,但我正在查看/Xcode3/usr/include并且那里并没有那么多。

1 个答案:

答案 0 :(得分:9)

如果在Lion上执行Xcode 3.2.6的经典安装,Xcode工具集将被禁用且未安装。这就是Xcode3/usr/bin不存在的原因。

我建议你阅读以下帖子(在进一步阅读之前阅读这两篇文章)。他们描述了欺骗安装程序安装所有内容的技巧。

然后,您可以应用the trick from the SO entry来恢复Xcode中的PPC支持。

注意:我没有测试过上述步骤,但我很乐意听到您的反馈意见。希望它有所帮助。

编辑2011年9月4日:我已经设法在Lion机器上进行了一些实验并获得了一些结果。我收集了他们on my blog