我们如何恢复对 Xcode 4 的 ppc/ppc64 以及完整的 10.4/10.5 SDK 支持?
由于 Apple 仅随 Xcode4 附带 SDK 10.6,因此使用 Xcode4 开发 PPC 应用程序变得不可能。虽然可以使用 Xcode4 开发也可以在 10.5 甚至 10.4 系统上运行的应用程序(通过选择 SDK 10.6,但部署目标为 10.5 或 10.4),但它们只能在 Intel Mac 上运行,因为您至少需要 SDK 10.5构建 PPC 应用程序。
此外,还有一些罕见的情况,您确实需要针对 10.6 之前的 SDK 进行构建以获得完整的平台支持,例如,如果某些已弃用的功能已从 10.6 SDK 中完全消失,但您必须使用它,并且动态链接不是在这些情况下总是最好的选择。另外,链接到早期的 SDK 有时会简化开发,因为您不应该使用的功能会导致与早期操作系统版本的不兼容,并且该功能将不可用,并且任何使用它的尝试都会立即导致编译器或链接器错误。
最后但并非最不重要的一点是,Apple 还从 Xcode4 中删除了 GCC 4.0 支持,这可能是某些软件正确构建所必需的,并且 Apple 从未允许在使用 SDK 10.4 时使用 GCC 4.2 编译软件,尽管我几乎不相信这真的会导致任何问题,毕竟使用 GCC 4.2 和 SDK 10.6 构建的软件也可以在 Mac OS 10.4 上运行,没有任何问题,只要部署目标设置正确并且没有使用 MacOS 10.4 下不可用的功能。
当然,您始终可以在 Xcode4 旁边并行安装 Xcode3,但这意味着您必须放弃 Xcode4 的所有(很棒?)新功能,并继续使用过时的 Xcode3 IDE。如果您还可以在与新项目相同的 IDE 中管理所有旧项目并从任何可用的新功能中受益,那肯定会更好。在可预见的将来,并非所有项目都可以采用 10.6 或 Intel。此外,我坚决反对在真正必要之前取消对旧平台的支持。
我们可以在 Xcode4 中恢复此功能吗?
Since Apple only ships SDK 10.6 with Xcode4, developing PPC applications with Xcode4 became impossible. While it is possible to develop applications with Xcode4 that can also run on 10.5 and maybe even on 10.4 systems (by selecting SDK 10.6, but deployment target 10.5 or 10.4), they will only run on Intel Macs because you need at least SDK 10.5 for building PPC applications.
Further there are some rare cases, where you really need to build against an SDK prior to 10.6 for full platform support, e.g. if certain deprecated functionality has vanished completely from the 10.6 SDK, but you'll have to use it and dynamic linking is not always the best option in those cases. Also linking against an earlier SDK sometimes will ease development as functionality you are not supposed to use, as it would cause incompatibility to earlier OS versions, won't be available and any attempt to use it anyhow immediately leads to compiler or linker errors.
Last but not least Apple has also removed GCC 4.0 support from Xcode4, which may be necessary for certain software to build correctly and Apple has never allowed to compile software with GCC 4.2 when using SDK 10.4, even though I hardly believe that this would really cause any issues, after all software built with GCC 4.2 and SDK 10.6 can also run on Mac OS 10.4 without any issues as long as the deployment target has been set correctly and no functionality that is unavailable under MacOS 10.4 has been used.
Of course you can always have a parallel installation of Xcode3 next to Xcode4, but that means you must forgo all the (great?) new features of Xcode4 and keep working with the outdated Xcode3 IDE. It would certainly be much better if you could also manage all your old projects within the same IDE as your new ones and benefit from any new features available. Not all projects can be made 10.6 or Intel only in the foreseeable future. Further I'm strictly against abolishing support for older platforms earlier than would be really necessary.
Can we restore this functionality to Xcode4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
简单的回答是:是的,我们可以!
在讨论“如何完成”部分之前,这里有一些关于我的补丁/黑客/修复的说明。从一开始,主要目标就是:
将所有修改保持在绝对最低限度。
我们希望尽可能保持 Xcode 设置的原始状态。
无论如何,尽量避免修补或修改任何文件。
我们希望所有文件保持不变并保留其原始内容。
除非绝对必要,否则尽量避免移动或复制文件。
我能够实现所有这些目标。几乎所有事情都是通过创建符号链接来完成的。只需替换一个现有的符号链接,我们将在替换之前对其进行备份,以防万一。
如果您不是终端操作专家,我强烈建议您将我回复中的所有终端命令复制/粘贴到您的终端,以避免拼写错误。请记住,即使是空格、引用,尤其是大写也很重要。逐行复制/粘贴它们,一次不要超过一行,并在每粘贴一行后按回车键以执行命令。如果任何操作提示您输入密码,这将是当前登录的管理员用户的密码(打字时不会显示您的击键,这是正常现象,不用担心,只需继续输入密码并按回车键即可;重新- 如果您有拼写错误,请尝试并再次收到提示)。
先决条件
在开始之前,请确保满足以下条件:
第 1 步:安装 Xcode3
重要:请勿安装 Xcode3 的“系统工具”或“Unix Development”软件包。
您是否要安装“Mac OS X 10.4 SDK”和/或“文档”取决于您。如果是带有 iOS SDK 的 Xcode3,则是否安装这些也取决于您。
您可以自由选择安装的任何目标文件夹。对于本指南,我选择了“/Xcode3”,但您可以随意选择其他的。只需确保相应地更改所有终端命令即可。
此处给出的步骤顺序通常并不重要,但我强烈建议您不要交换步骤 1 和步骤 2。Xcode 总是在所选目标文件夹之外安装几个文件,相信我,最终您想要的磁盘上这些文件的 Xcode4 版本。通过在 Xcode4 之前安装 Xcode3,您可以确保 Xcode4 会在必要时覆盖这些文件。我曾经交换了步骤 1 和 2,最后我遇到了一些相当奇怪的问题,这些问题可能与错误的顺序有关(我不能肯定地说,但在以正确的顺序重新安装后,问题就消失了)。
第 2 步:安装 Xcode4
选择您喜欢的任何包。建议安装“系统工具”,但并非绝对必要(尽管大多数人迟早会错过该功能)。
同样,请随意选择您喜欢的任何目标文件夹。在本指南中,我选择了普通目标文件夹“/Developer”,如果您采用不同的目标文件夹,请相应地更改所有终端命令。
步骤 3:恢复 10.4/10.5 SDK 支持
切换到终端窗口并运行以下命令:
当然,如果您还在步骤 1 中安装了 SDK 10.4,则仅运行 10.4u 的命令。
这足以将 SDK 10.5(可能还包括10.4)回到Xcode4中的选择列表。如果你喜欢就试试吧。启动Xcode4,打开一个项目,尝试更改所选的SDK。这很容易,是吧?在继续下一步之前,请务必再次关闭 Xcode4(应用程序,而不仅仅是窗口)。
步骤 4:恢复 GCC 4.0 支持
如果您尚未安装 MacOS 10.4 SDK 或者您不打算使用它,则可以安全地跳过此步骤并继续执行步骤 5。
要使用 SDK 10.4,您必须使用GCC 4.0、GCC 4.2 不起作用。苹果声称 GCC 4.2 与 SDK 10.4 不兼容,好吧,如果你问我,这是一个骗局。我已经不止一次地覆盖了这个限制,并且从来没有因此而出现过最微小的问题。修改 SDK 10.4 很容易,以便 Xcode 允许您使用 GCC 4.2,但我的目标是避免所有文件修改,因此我们只需将 GCC 4.0 支持添加回 Xcode,这也是一件好事,因为有些项目确实依赖于GCC 4.0(例如,GCC 4.2 中存在一些错误,导致有效的内联汇编代码无法正确编译,而相同的代码在GCC 4.0 和GCC 4.4 上可以完美编译)。
回到终端:
现在我们已经恢复了对 GCC 4.0 的完整支持,只是在 Xcode4 中仍然无法选择 GCC 4.0。这是因为Xcode4不再有GCC 4.0编译器插件。幸运的是,Xcode3 插件也可以在 Xcode4 中使用,只是位置发生了根本性的变化。苹果现在将这些插件隐藏在捆绑包的深处,并且似乎只有那里的插件才起作用,将它们放在原来的位置似乎没有效果。
现在再次启动 Xcode4,打开一个项目并尝试选择编译器。您应该让 GCC 4.0 重新出现在列表中。现在您实际上已经可以选择 SDK 10.4 或 10.5、GCC 4.0,并且构建 PPC 二进制文件应该没有问题。只需为“架构”构建设置选择“其他...”并手动输入“ppc”,然后更改“Valid” Architectures”还包括“ppc”。我们几乎完成了,只是尝试使用 GCC 4.2 和 SDK 10.5 构建 PPC 二进制文件仍然会失败。
步骤 5:恢复 GCC 4.2 的 PPC 支持
由于 Apple 在 Xcode4 中仅支持 Intel 平台,因此并非所有 GCC 4.2 工具都带有 PPC 支持。有一个重要的工具不支持 PPC,该工具名为“as”,它就是 GNU Assembler。要使用 GCC 4.2 编译 ppc/ppc64 二进制文件,我们需要使用支持 ppc/ppc64 的“as”版本。这是唯一一个文件(实际上它也是一个符号链接),我们必须首先将其移到一边(制作备份副本),然后才能用符号链接替换它:
步骤 6:没有 步骤 6 各位,
这就是全部了。考虑到这有多容易,你可以想象苹果肯定不会放弃 SDK 10.4/10.5 或 ppc/ppc64 或 GCC 4.0 支持,因为这是必需的,他们放弃了所有这些,因为他们想放弃它。
我希望这个设置对你和我一样有效。我已经能够在 Xcode4 中编译所有旧项目,无需进行任何重大更改,除了必须到处更改搜索路径之外。
PS:
我在这里回答我自己的问题可能看起来很奇怪,但由于我自己找到了如何解决这个问题,我想与社区分享我的知识,因为我相信这对所有 MacOS 来说都是非常有价值的输入那里的开发商。这个问题已经在很多地方被问过很多次了,到目前为止,我从未见过有人提出类似的解决方案。分享财富、传播知识等等,你知道我的意思。
如果您仍有问题/疑问:
如果您对本主题还有其他问题,或者在正确构建旧项目时仍然遇到问题,请按照 Stack Overflow 的设计目的进行操作:单击“提问”此页面的右上角并创建一个新问题。这样整个社区就可以帮助您解决这些问题,因为这些问题可能与此黑客行为没有直接(甚至可能不是间接)相关。
我建议您在问题一开始就提到您确实应用了此技巧这一事实。也许您甚至想直接链接到这个问题,以便从未听说过这个黑客的人可以轻松查找它。否则,当你提到 SDK 10.4/10.5、PPC 或 GCC 4.0 与 Xcode4 结合使用时,大多数人会感到相当困惑,而 Xcode4 官方并不支持这些。如果您忘记提及此黑客行为,您可能会得到相当愚蠢的评论,而不是体面的回复。
请不要在这里发布您的疑问或问题作为回复或评论。将它们作为回复发布是没有意义的,因为它们不是回复,除了使用评论之外,人们无法回复您,并且评论可能无法提供足够的空间来对您的问题进行体面的答复或对您的问题提供体面的解决方案。问题。将它们作为评论发布意味着您的空间有限,并且跟踪回复评论将很困难,因为评论没有树状层次结构(此外,它们仍然为体面的回复/解决方案提供很小的空间)。谢谢。
当然,我们始终欢迎其他类型的评论以及对原始问题的更好答复;-)
The quick answer is: Yes, we can!
Before I get to the "how it is done" part, here are some notes about my patch/hack/fix. Right from the start the major goals have been:
Keep all modifications to an absolute minimum.
We want to keep the Xcode setups as original as possible.
By all means, try to avoid patching or modifying any files.
We want all files to stay untouched and keep their original content.
Try to avoid moving or copying files around, unless absolutely necessary.
I was able to keep all those goals. Almost everything is done by creating symlinks. Only a single existing symlink had to be replaced and we'll back it up before replacement, just in case.
If you are no expert on terminal operations, I strongly advise you to copy/paste all terminal commands from my reply to your terminal, to avoid typos. Bear in mind that even spacing, quoting and especially capitalization can be important. Copy/paste them line by line, never more than one line at once and hit return after each pasted line to execute the command. Should any operation ever prompt you for a password, this will be the password of the currently logged in administrator user (your keystrokes are not displayed while typing, this is normal, don't worry, just keep typing the password and hit return; re-try if you had a typo and get prompted again).
Prerequisite
Before we can start, make sure the following conditions are true:
Step 1: Installing Xcode3
Important: Do not install "System Tools" or "Unix Development" package of Xcode3.
Whether you want to install "Mac OS X 10.4 SDK" and/or "Documentation" is up to you. If that is a Xcode3 with iOS SDKs, whether you install those or not is also up to you.
You are free to choose any destination folder for your installation. For this guide I have chosen "/Xcode3", but feel free to pick a different one. Just make sure to alter all terminal commands accordingly.
The order of the steps given here is usually not really important, but I strongly advise you to not swap step 1 and step 2. Xcode always installs a couple of files outside of the chosen destination folder and trust me, in the end you want the Xcode4 versions of those files on your disk. By installing Xcode3 before Xcode4, you can be sure that Xcode4 will overwrite those files if necessary. I once swapped steps 1 and 2 and in the end I had some rather strange issues that might have been related to the incorrect order (I cannot say for sure, but after re-installing in the correct order the issues were gone).
Step 2: Installing Xcode4
Chose any packets you like. Installing "System Tools" is advisable, but not strictly necessary (though most people will sooner or later miss that functionality).
Again, feel free to pick any target folder you like. For this guide I chose the normal target folder "/Developer", if you take a different one, alter all terminal commands accordingly.
Step 3: Restoring 10.4/10.5 SDK Support
Switch to your terminal window and run the following commands:
Of course only run the command for 10.4u if you also installed SDK 10.4 in step 1.
This is enough to bring the SDKs 10.5 (and possibly 10.4) back to the selection list in Xcode4. Give it a try if you like. Fire up Xcode4, open a project, try changing the selected SDK. That was easy, huh? Be sure to close Xcode4 again (the application, not just the window) before proceeding with the next step.
Step 4: Restoring GCC 4.0 Support
If you have not installed MacOS 10.4 SDK or if you don't plan to ever use it, you can safely skip this step and proceed with step 5.
To use SDK 10.4, you'll have to use GCC 4.0, GCC 4.2 won't work. Apple claims that GCC 4.2 is not compatible with SDK 10.4, well, if you ask me, this is a hoax. I have already overwritten this limitations more than once and there was never the tiniest issue because of it. It would be easy to modify SDK 10.4 so that Xcode will allow you to use GCC 4.2 for it, but my goal was to avoid all file modifications, so we just add GCC 4.0 support back to Xcode, which is also a good thing, because some projects really depend on GCC 4.0 (e.g. there are some bugs in GCC 4.2 that prevent valid inline assembly code to compile without errors, while the same code compiles flawlessly on GCC 4.0 and GCC 4.4).
Back to terminal:
Right now we have restored full GCC 4.0 support except for the fact that GCC 4.0 is still not selectable in Xcode4. That is because Xcode4 has no GCC 4.0 compiler plug-in any longer. Fortunately the Xcode3 plug-in also works in Xcode4, only the position has radically changed. Apple now hides those plug-ins deep within a bundle and only plug-ins there seem to work, placing them to their old position seems to have no effect.
Now fire up Xcode4 again, open a project and try selecting the compiler. You should have GCC 4.0 back on the list. Now you can actually already select SDK 10.4 or 10.5, GCC 4.0 and you should have no issue to build a PPC binary. Just select "Other..." for the "Architecture" build setting and manually enter "ppc", then alter "Valid Architectures" to also include "ppc". We are almost done, except that trying to build a PPC binary using GCC 4.2 and SDK 10.5 will still fail.
Step 5: Restoring PPC Support for GCC 4.2
Since Apple is only supporting Intel platforms in Xcode4, not all GCC 4.2 tools have been built with PPC support. There is one important tool that has no PPC support, the tool is named "as" and it is the GNU Assembler. To compile ppc/ppc64 binaries with GCC 4.2 we need to use an "as" version with ppc/ppc64 support. This is the one and only file (actually it also a symlink) we have to first move aside (making a backup copy) before we can replace it by a symlink:
Step 6: There is No Step 6
That's all folks. Considering how easy that was, you can imagine that Apple has certainly not dropped SDK 10.4/10.5 or ppc/ppc64 or GCC 4.0 support because this was a necessity, they dropped all that because they wanted to drop it.
I hope this setup works as well for you as it does for me. I have been able to compile all my old projects in Xcode4 without any major changes, except for having to alter a search path here and there.
PS:
It may look strange that I answer my own question here, but since I have found out how to solve this problem all by myself, I'd like to share my knowledge with the community, because I believe this is really valuable input to all MacOS developers out there. This question has been asked so many times in so many places and so far I have never seen anyone coming up with a similar fix. Share the wealth, spread the knowledge and so on, you know what I mean.
If You Still Have Issues/Questions:
If you have additional questions regarding this topic or if you still have problems to build your old projects correctly, please do what Stack Overflow has been designed for: Click on "Ask Question" in the upper right corner of this page and create a new question. That way the whole community can help you solving those issues, since the issues may not directly (maybe not even indirectly) be related to this hack.
I would recommend you mention the fact that you did apply this hack at the very beginning of your question. Maybe you even want to directly link to this question, so that people, who never heard of this hack, can easily look it up. Otherwise most people will get rather confused when you mention SDK 10.4/10.5, PPC or GCC 4.0 in combination with Xcode4, which officially supports neither of these. You might get rather stupid comments instead of decent replies if you forget to mention this hack.
Please refrain from posting your questions or issues here either as replies or as comments. Posting them as replies makes no sense because they are no replies and there is no way how people can reply back to you, other then using comments, and comments may not offer enough room for a decent reply to your question or a decent solution to your problem. And posting them as comments means you are limited to very little room and tracking reply comments will be hard as comments have no tree-like hierarchy (further they will still offer to little room for decent replies/solutions). Thank you.
Of course other kind of comments as well as better replies to the original question are always welcome ;-)
另一种仅使用 Xcode4 的简单方法,不再需要 Xcode3。
编辑:
对于 Xcode 4.1,
您只能将 gcc-4.2 用于 PowerPC。并且需要“-isysroot /Developer/SDKs/MacOSX10.6.sdk”选项,因为10.7 SDK不再支持PowerPC。
Another easy way with only Xcode4, Xcode3 is no longer needed.
EDITS:
For Xcode 4.1,
You can use gcc-4.2 only for PowerPC. And “-isysroot /Developer/SDKs/MacOSX10.6.sdk” option is required, because 10.7 SDK doesn't support PowerPC any more.
我收集了本页、Mac OS X Hints、splhack.org 以及此处引用的其他来源中的所有信息,并整理了一组 BASH 脚本,这些脚本可以使用以下任一方法自动恢复 PPC 和 GCC 4.0 支持的过程: XCode 3安装或者只是XCode 4自己的iPhone平台文件。
一如既往,谨慎使用!并请贡献任何修复或改进。截至本文发布时,这些脚本仅在我自己的系统上进行了测试。
您可以从 GitHub 下载它们:
I've gathered together all the information from this page, Mac OS X Hints, splhack.org, and the other sources cited here, and put together a set of BASH scripts which automate the process of restoring PPC and GCC 4.0 support using either an XCode 3 installation or just XCode 4's own iPhone platform files.
As always, use with caution! and please contribute any fixes or improvements. These scripts have only been tested on my own system as of this posting.
You can download them from GitHub:
如果您希望 gcc 也从命令行工作,(以及上面的内容)您还需要:
If you want gcc to work from the command line as well, (as well as the above) you'll also need to:
这仍然适用于 AppStore 中的 Xcode 4.3.2 - 该版本的所有内容都独立包含在应用程序包中。如原始提示所示,首先安装 Xcode 3.2.6*,然后从 AppStore 下载 Xcode 4。
然后执行以下符号链接魔术:
最后两行在符号链接中将 darwin10 重命名为 darwin11 - 我猜测 OS X 的未来版本将要求对其进行适当更新。
要在 Lion 上安装 Xcode 3.2.x,请安装 Xcode 磁盘映像,打开终端,输入命令(使用 bash,或者如果您更改了默认 shell,则使用等效命令):
导出 COMMAND_LINE_INSTALL=1
打开“/Volumes/Xcode 和 iOS SDK/Xcode 和 iOS SDK.mpkg”
您还需要将时钟设置回 2012 年 3 月 31 日之前的日期,否则安全证书将在安装过程中验证失败。显然,您可以在安装后安全地将日期再次更改回来!
This still works with Xcode 4.3.2 from the AppStore - the version where everything is self-contained in an App bundle. As in the original hint, install Xcode 3.2.6 first* and then download Xcode 4 from the AppStore.
Then do the following symlink magic:
The last two lines rename darwin10 to darwin11 in the symlink - I'm guessing future versions of OS X will require this to be updated as appropriate.
To install Xcode 3.2.x on Lion, mount the Xcode disk image, open Terminal, enter the commands (using bash, or the equivalent commands if you've changed your default shell):
export COMMAND_LINE_INSTALL=1
open "/Volumes/Xcode and iOS SDK/Xcode and iOS SDK.mpkg"
You'll also need to set the clock back to a date prior to 31st March 2012 otherwise security certificates will fail validation during installation. You can safely change the date back again after installation obviously!
Frédéric Devernay 有一个名为 xcodelegacy 的 GitHub 项目,它在 Xcode 5.1.1 上对我来说效果非常好,并且只需要很少的工作就可以运行它,只需要一些下载。
通过他的项目,我成功创建了包含 ppc 和 i386 架构的通用二进制文件,这些二进制文件是使用 GCC 4.0 使用 10.4 SDK 编译的,所有这些都来自在 Yosemite 上运行的 Xcode 5.1.1。
我已经证实创建的通用二进制文件在 10.5 Leopard 和 Yosemite 本身上运行良好。
主页在这里: http://devernay.free.fr/hacks/xcodelegacy
Git hub 项目在这里: https://github.com/devernay/xcodelegacy
Frédéric Devernay has a GitHub project called xcodelegacy which works fantastic for me on Xcode 5.1.1, and needs very little work to get it going, just some downloading.
Using his project, I've managed to create universal binaries containing both ppc and i386 architectures compiled with the 10.4 SDK using GCC 4.0, all from within Xcode 5.1.1 running on Yosemite.
I've verified myself that the universal binaries created work fine on 10.5 Leopard and on Yosemite itself.
Home page here: http://devernay.free.fr/hacks/xcodelegacy
Git hub project here: https://github.com/devernay/xcodelegacy
如果有人需要在 Xcode 4.3 和 4.5 中恢复旧的 SDK 和 PPC 编译器,这是我想出的一个脚本。请注意,您需要在脚本开头设置 Xcode 应用程序包的路径和 Xcode 3.2.6 安装的路径。
如果您使用 Xcode 4.3,则无需符号链接 10.6 SDK,因为它附带了一个。
此外,该脚本不会恢复 gcc 4.2,因为这样做会产生很多文件名冲突。我的目标是恢复 PPC 编译器,4.0 对我来说已经足够了。
In case someone need to restore old SDKs and PPC compiler in Xcode 4.3 and 4.5, this is a script I came up with. Note you need to set the path to the Xcode app bundle and path to Xcode 3.2.6 install at the beginning of the script.
You don't need to symlink 10.6 SDK if you are using Xcode 4.3 since it comes with one.
Also the script does not restore gcc 4.2 since there are a lot of filename conflicts doing that. My goal is to restore PPC compiler and 4.0 is good enough for me.
如果有一个包可以将这些文件安装到 XCode 4 实现中,将会非常有用。 (或 tarball)。
仅供参考:Xcode3 的 3.2.6 不包含 ppc 架构。但我的电脑上有 Leopard 的备份。所以我复制了那个,似乎有效。 (使用 /usr/libexec/gcc/darwin/ppc/as )。
考虑到 gcc 和 as 都是开源的,唯一可能不可再分发的东西是 xcode 插件和 10.4 SDK,对吧?
It would be useful to have a package to just install these files into an XCode 4 implementation. (or a tarball).
FYI: 3.2.6 of Xcode3 does not include an as with ppc architecture. But I had a backup of Leopard on my computer. So I copied that one, seems to work. (Use /usr/libexec/gcc/darwin/ppc/as ).
Considering that both gcc and as are open source the only stuff that may not be redistributable is the xcode plugin and the 10.4 SDK right?