我们如何将 ppc/ppc64 以及完整的 10.4/10.5 SDK 支持恢复到 Xcode 4? [英] How can we restore ppc/ppc64 as well as full 10.4/10.5 SDK support to Xcode 4?

查看:25
本文介绍了我们如何将 ppc/ppc64 以及完整的 10.4/10.5 SDK 支持恢复到 Xcode 4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 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 吗?

解决方案

快速回答是:是的,我们可以!

在我进入它是如何完成"部分之前,这里有一些关于我的补丁/黑客/修复的说明.从一开始,主要目标就是:

  1. 尽量减少所有修改.
    我们希望尽可能保持 Xcode 设置的原始性.

  2. 无论如何,尽量避免修补或修改任何文件.
    我们希望所有文件都保持原样并保留其原始内容.

  3. 除非绝对必要,否则尽量避免移动或复制文件.

我能够保持所有这些目标.几乎所有的事情都是通过创建符号链接来完成的.只需要替换一个现有的符号链接,我们会在替换前对其进行备份,以防万一.

如果您不是终端操作专家,我强烈建议您将我回复中的所有终端命令复制/粘贴到您的终端,以避免输入错误.请记住,即使是间距、引用,尤其是大写也很重要.一行一行地复制/粘贴它们,一次不要超过一行,并在每一行粘贴后按回车来执行命令.如果任何操作提示您输入密码,这将是当前登录的管理员用户的密码(键入时不会显示您的击键,这是正常的,不要担心,只需继续输入密码并按回车键即可;重新- 如果您有拼写错误并再次收到提示,请尝试).

先决条件

在我们开始之前,请确保以下条件成立:

  • 您以管理员用户身份登录.
  • 您已启动 Terminal.app(应用程序/实用程序)并打开一个终端窗口.
  • 您有 Xcode3(例如 3.2.5)和 Xcode4 磁盘映像 (DMG) 或安装程序的副本.
  • 如果您已经安装了任一 Xcode 版本,请考虑先卸载它,这样您就可以从全新/干净的设置开始.卸载 Xcode 不会删除您的首选项、配色方案或键绑定自定义.理想情况下,您从当前未安装 Xcode 版本(既不是 3 也不是 4)的系统开始.

第一步:安装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 支持

切换到终端窗口并运行以下命令:

cd/Developer/SDKs须藤 ln -s/Xcode3/SDKs/MacOSX10.4u.sdk .须藤 ln -s/Xcode3/SDKs/MacOSX10.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 不起作用.Apple 声称 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 上可以完美编译).

回到终端:

cd/Developer/usr/bin须藤 ln -s/Xcode3/usr/bin/*4.0* .cd/Developer/usr/libexec/gcc/powerpc-apple-darwin10须藤 ln -s/Xcode3/usr/libexec/gcc/powerpc-apple-darwin10/4.0.1 .

现在我们已经恢复了对 GCC 4.0 的完整支持,除了 GCC 4.0 在 Xcode4 中仍然无法选择.那是因为 Xcode4 不再有 GCC 4.0 编译器插件了.好在 Xcode3 插件也适用于 Xcode4,只是位置发生了根本性的变化.Apple 现在将这些插件隐藏在一个包的深处,只有那里的插件似乎可以工作,将它们放在旧位置似乎没有任何效果.

cd/Developer/Library/Xcode/PrivatePlugInscd Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-inssudo ln -s "/Xcode3/Library/Xcode/Plug-ins/GCC 4.0.xcplugin" .

现在再次启动 Xcode4,打开一个项目并尝试选择编译器.您应该让 GCC 4.0 重新出现在列表中.现在您实际上已经可以选择 SDK 10.4 或 10.5、GCC 4.0,并且您应该可以毫无问题地构建 PPC 二进制文件.只需为Architecture"构建设置选择Other..."并手动输入ppc",然后更改Valid"体系结构"还包括ppc".我们几乎完成了,只是尝试使用 GCC 4.2 和 SDK 10.5 构建 PPC 二进制文件仍然会失败.

第 5 步:恢复 GCC 4.2 的 PPC 支持

由于 Apple 仅在 Xcode4 中支持 Intel 平台,因此并非所有 GCC 4.2 工具都支持 PPC.有一个不支持 PPC 的重要工具,该工具名为as",它是 GNU 汇编器.要使用 GCC 4.2 编译 ppc/ppc64 二进制文件,我们需要使用支持 ppc/ppc64 的as"版本.这是唯一一个文件(实际上它也是一个符号链接),我们必须先移到一边(制作备份副本),然后才能用符号链接替换它:

cd/Developer/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1sudo mv as as.bak须藤 ln -s/Xcode3/usr/bin/as .

第 6 步:没有第 6 步

这就是所有人.考虑到那是多么容易,你可以想象 Apple 肯定没有放弃 SDK 10.4/10.5 或 ppc/ppc64 或 GCC 4.0 支持,因为这是必要的,他们放弃了所有这些,因为他们想放弃它.

我希望这个设置对你和我一样有效.我已经能够在 Xcode4 中编译我所有的旧项目而没有任何重大更改,除了必须在这里和那里更改搜索路径.

附注:
我在这里回答我自己的问题可能看起来很奇怪,但由于我已经找到了自己解决这个问题的方法,我想与社区分享我的知识,因为我相信这对所有 MacOS 来说都是非常有价值的输入开发人员在那里.这个问题在很多地方被问过很多次,到目前为止我从未见过有人提出类似的解决方案.分享财富,传播知识等等,你懂我的意思.


如果您仍有问题/疑问:

如果您对此主题有其他问题,或者您仍然无法正确构建旧项目,请按照 Stack Overflow 的设计目标进行操作:单击此页面右上角的提问"并创建一个新问题.这样整个社区都可以帮助您解决这些问题,因为这些问题可能与此 hack 没有直接(甚至可能不是间接)相关.

我建议您提及您确实在问题的一开始就应用了此 hack 的事实.也许您甚至想直接链接到这个问题,以便从未听说过这个 hack 的人可以轻松查找.否则当你提到 SDK 10.4/10.5、PPC 或 GCC 4.0 与 Xcode4 结合时,大多数人会感到相当困惑,而 Xcode4 官方不支持这些.如果你忘记提及这个 hack,你可能会得到相当愚蠢的评论而不是体面的回复.

请不要在此处以回复或评论的形式发布您的问题或问题.将它们作为回复发布是没有意义的,因为它们不是回复,并且人们无法回复您,除了使用评论之外,评论可能无法提供足够的空间来对您的问题进行体面的回复或对您的问题提供体面的解决方案问题.将它们作为评论发布意味着您被限制在很小的空间内,并且由于评论没有树状层次结构,因此很难跟踪回复评论(此外,它们仍然为体面的回复/解决方案提供很小的空间).谢谢.

当然,其他类型的评论以及对原始问题的更好回复总是受欢迎的;-)

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?

解决方案

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:

  1. Keep all modifications to an absolute minimum.
    We want to keep the Xcode setups as original as possible.

  2. By all means, try to avoid patching or modifying any files.
    We want all files to stay untouched and keep their original content.

  3. 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:

  • You are logged in as an administrator user.
  • You have started Terminal.app (Applications/Utilities) and a terminal window is open.
  • You have a copy of the Xcode3 (e.g. 3.2.5) and Xcode4 disk image (DMG) or installer available.
  • If you already have either Xcode version installed, consider uninstalling it first, so you can start with a fresh/clean setup. Uninstalling Xcode will not remove your preferences, color scheme or key binding customizations. Ideally you'd start with a system that has no Xcode version (neither 3 nor 4) currently installed.

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:

cd /Developer/SDKs
sudo ln -s /Xcode3/SDKs/MacOSX10.4u.sdk .
sudo ln -s /Xcode3/SDKs/MacOSX10.5.sdk .

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:

cd /Developer/usr/bin
sudo ln -s /Xcode3/usr/bin/*4.0* .

cd /Developer/usr/libexec/gcc/powerpc-apple-darwin10
sudo ln -s /Xcode3/usr/libexec/gcc/powerpc-apple-darwin10/4.0.1 .

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.

cd /Developer/Library/Xcode/PrivatePlugIns
cd Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins
sudo ln -s "/Xcode3/Library/Xcode/Plug-ins/GCC 4.0.xcplugin" .

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:

cd /Developer/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1
sudo mv as as.bak
sudo ln -s /Xcode3/usr/bin/as .

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 ;-)

这篇关于我们如何将 ppc/ppc64 以及完整的 10.4/10.5 SDK 支持恢复到 Xcode 4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆