简体   繁体   English

在Xcode 4.2和iOS SDK 5.0中使用gcc 4.2

[英]Use gcc 4.2 in Xcode 4.2 and iOS SDK 5.0

I just upgraded to Xcode 4.2 and iOS SDK 5 earlier today. 我今天刚刚升级到Xcode 4.2和iOS SDK 5。 But everything seems different with new compilers. 但是新的编译器似乎有些不同。

There are two "Compiler for C/C++/Objective-C" options now, "Apple LLVM compiler 3.0" and "LLVM GCC 4.2". 现在有两个“Compiler for C / C ++ / Objective-C”选项,“Apple LLVM编译器3.0”和“LLVM GCC 4.2”。 GCC 4.2 is missing. 缺少GCC 4.2。

Apple LLVM compiler 3.0, builds really fast(I like that), gives me 999+ warnings, and my game can no longer run. Apple LLVM编译器3.0,构建速度非常快(我喜欢它),给了我999+警告,我的游戏再也无法运行了。 It looks like there's some differences on memory, and it crashes when loading our game's scripts. 看起来在内存上存在一些差异,并且在加载我们的游戏脚本时它会崩溃。

LLVM GCC 4.2 is so god damn slow, I still cannot finish one build after hours on my i7 machine. LLVM GCC 4.2真是太神了,我仍然无法在i7机器上完成一个小时的构建。

And, one more thing is our engine uses gcc command lines to build(instead of xcode). 而且,还有一件事是我们的引擎使用gcc命令行来构建(而不是xcode)。

So, it leads to one question, how can I use gcc 4.2 in Xcode 4.2 ? 因此,它导致了一个问题, 我如何在Xcode 4.2中使用gcc 4.2 Is that even possible? 这甚至可能吗?

Here is a way to enable compiling with gcc 4.2 in xcode 4.2 . 这是一种在xcode 4.2中使用gcc 4.2进行编译的方法。 Most of this is done via command line so when you see lines like this: [ 15:30 jon@MacBookPro / ]$ , you need to open up a Terminal and run the command after the $ . 大多数这是通过命令行完成的,所以当你看到这样的行: [ 15:30 jon@MacBookPro / ]$ ,你需要打开一个终端并在$之后运行命令。

No files or directories are removed or deleted in this process, so it is easy to undo if you need to compile with LLVM in the future. 在此过程中不会删除删除任何文件或目录,因此如果您将来需要使用LLVM进行编译,则很容易撤消。

  1. Download - but do not install yet - xcode_4.1_for_lion.dmg or xcode_4.1_for_snow_leopard.dmg 下载-但是不要安装尚未 - xcode_4.1_for_lion.dmgxcode_4.1_for_snow_leopard.dmg

  2. Now, follow these steps to install Xcode 4.1 into /Developer-4.1 : 现在,按照以下步骤将Xcode 4.1安装到/Developer-4.1

    1. Backup the working /Developer directory (where Xcode 4.2 is installed) 备份working /Developer目录(安装Xcode 4.2的地方)

    2.  [ 15:30 jon@MacBookPro / ]$ sudo mv -v /Developer /Developer-4.2 
    3. Run the Xcode 4.1 installer using the default install location ( /Developer ) 使用默认安装位置( /Developer )运行Xcode 4.1安装程序

    4. Move the new Xcode 4.1 installation to /Developer-4.1 : 将新的Xcode 4.1安装移至/Developer-4.1

       [ 15:30 jon@MacBookPro / ]$ sudo mv -v /Developer /Developer-4.1 
    5. Move the Xcode 4.2 developer directory back to /Developer : 将Xcode 4.2开发人员目录移回/Developer

       [ 15:30 jon@MacBookPro / ]$ sudo mv -v /Developer-4.2 /Developer 
  3. Edit the Xcode 4.2 GCC 4.2.xcspec file to get gcc 4.2 to show in the list of compiler options [1] : 编辑Xcode 4.2 GCC 4.2.xcspec文件,使gcc 4.2显示在编译器选项列表中[1]

     [ 15:30 jon@MacBookPro / ]$ sudo vi "/Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/GCC 4.2 (Plausible Blocks).xcplugin/Contents/Resources/GCC 4.2.xcspec" 
    • Change lines 41 and 42 from this: 从这里改变第4142行:

       ShowInCompilerSelectionPopup = NO; IsNoLongerSupported = YES; 
    • To This: 对此:

       ShowInCompilerSelectionPopup = YES; IsNoLongerSupported = NO; 
  4. Backup the Xcode 4.2 iOS/Simulator Framework usr directories: 备份Xcode 4.2 iOS / Simulator Framework usr目录:

     [ 15:30 jon@MacBookPro / ]$ sudo mv -v /Developer/Platforms/iPhoneOS.platform/Developer/usr /Developer/Platforms/iPhoneOS.platform/Developer/usr.backup [ 15:30 jon@MacBookPro / ]$ sudo mv -v /Developer/Platforms/iPhoneSimulator.platform/Developer/usr /Developer/Platforms/iPhoneSimulator.platform/Developer/usr.backup 
  5. Copy Xcode 4.1 iOS/Simulator Framework usr directories to Xcode 4.2: 将Xcode 4.1 iOS / Simulator Framework usr目录复制到Xcode 4.2:

     [ 15:30 jon@MacBookPro / ]$ sudo cp -rv /Developer-4.1/Platforms/iPhoneOS.platform/Developer/usr /Developer/Platforms/iPhoneOS.platform/Developer/usr [ 15:30 jon@MacBookPro / ]$ sudo cp -rv /Developer-4.1/usr /Developer/Platforms/iPhoneSimulator.platform/Developer/usr 
  6. Copy the gcc and info iOS SDK library directories from Xcode 4.1 to Xcode 4.2 [2] : gccinfo iOS SDK库目录从Xcode 4.1复制到Xcode 4.2 [2]

     [ 15:30 jon@MacBookPro / ]$ sudo cp -rv /Developer-4.1/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/gcc /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/gcc [ 15:30 jon@MacBookPro / ]$ sudo cp -rv /Developer-4.1/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/info /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/info 
  7. Compile using gcc-4.2! 使用gcc-4.2编译!

    xcode 4.2中CGG 4.2的屏幕截图


This is a blog post I've written with a little more info about this process. 这是一篇博文,我写了一些关于这个过程的更多信息。 Feel free to leave a comment on the blog if you run into any issues or have any questions. 如果您遇到任何问题或有任何问题,请随时在博客上发表评论。


[1] If opening from a command line (using something like vi , emacs , nano , etc) make sure to either enclose the path in quotes "/long path/with spaces/in it/file.xcspec" or escape the spaces /some/long\\ path/with\\ spaces/in\\ it/file.xcspec [1]如果从命令行打开(使用类似viemacsnano等的东西),请确保将路径括在引号“/ long path / with spaces / in / file.xcspec”中,或者转义空格/ some / long \\ path / with \\ spaces / in \\ it / file.xcspec

[2] This is necessary because the iPhoneOS.platform SDK has its own seperate /usr/lib directories but the iPhoneSimulator.platform SDK does not [2]这是必要的,因为iPhoneOS.platform SDK有自己的单独的/usr/lib目录,但iPhoneSimulator.platform SDK没有

In this years WWDC, Apple stated that GCC is no longer available in XCode 4.2. 在今年的WWDC中,Apple表示GCC已不再适用于XCode 4.2。 However, they stated that the LLVM compiler supports the same command line switches as GCC. 但是,他们表示LLVM编译器支持与GCC相同的命令行开关。

I tried to update this for the applified version of Xcode. 我试图为适用的Xcode版本更新这个。 This will show how to install Xcode 4.4.x with full gcc support. 这将显示如何安装Xcode 4.4.x并支持完整的gcc。

You need: Mac OSX Lion - this is important, don't try with Mountain Lion! 你需要:Mac OSX Lion - 这很重要,不要试试Mountain Lion!

You need: a copy of Xcode 4.1 for Lion. 您需要:Lion的Xcode 4.1副本。 Download from Apple with your dev account. 使用您的开发者帐户从Apple下载。 Don't install yet. 还没安装。

Now install Xcode 4.4.x from Apple via Mac App Store. 现在通过Mac App Store从Apple安装Xcode 4.4.x.

After this is done, you will have xcode 4.4.x in your applications directory. 完成此操作后,您的应用程序目录中将包含xcode 4.4.x.

Depending on user rights, you will have to confirm many of the actions with your admin password. 根据用户权限,您必须使用管理员密码确认许多操作。 Just do so when necessary. 必要时这样做。 If you damage your system, you are on your own (that should not happen though, as Xcode has been applified). 如果你损坏你的系统,你就是你自己(不应该发生,因为Xcode已经被应用了)。

Open Xcode 4.4.x via right mouse click and "Show Package Contents" and then navigate to the gcc 4.2 plugin here: 通过鼠标右键单击和“显示包内容”打开Xcode 4.4.x,然后在此处导航到gcc 4.2插件:

/Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/GCC 4.2.xcplugin/Contents/Resources/ /Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/GCC 4.2.xcplugin / Contents / Resources /

Open the file gcc 4.2.xcspec with a text editor. 使用文本编辑器打开文件gcc 4.2.xcspec。

Look at lines 41and 42. Make sure they look exactly as presented here (the values will be reversed in a fresh install). 查看第41和第41行。确保它们看起来与此处所示完全相同(值将在全新安装中反转)。

ShowInCompilerSelectionPopup = YES;
IsNoLongerSupported = NO;

Save and close. 保存并关闭。

Install Xcode 4.1 for Lion. 为Lion安装Xcode 4.1。

Now navigate to the developer directory at the root of your boot drive. 现在导航到启动驱动器根目录下的开发人员目录。

Navigate to /Developer/Platforms/iPhoneOS.platform/Developer/usr/ 导航到/Developer/Platforms/iPhoneOS.platform/Developer/usr/

copy the usr directory with command-c 使用command-c复制usr目录

switch back to xcode 4.4.x 切换回xcode 4.4.x.

navigate to: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/ 导航到:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/

paste the usr directory with command-v 使用command-v粘贴usr目录

now lion will try to merge the two directories. 现在狮子会尝试合并这两个目录。 Make sure to press "Keep Newer" 一定要按“保持更新”

Repeat with source: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr And target: /Applications/Xcode.app/Contents/Developer/Platforms/usr 重复源:/Developer/Platforms/iPhoneSimulator.platform/Developer/usr和目标:/Applications/Xcode.app/Contents/Developer/Platforms/usr

Again, merge and "Keep Newer" 再次,合并和“保持更新”

Navigate to: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib 导航至:/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib

Now copy the gcc directory by selecting it and using command-c 现在通过选择它并使用command-c复制gcc目录

Navigate into the Xcode 4.4.x app: 导航到Xcode 4.4.x应用程序:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib

Paste the gcc directory with command-v 使用command-v粘贴gcc目录

Repeat from /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib with 'info' directory target is again /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib 从/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib重复'info'目录目标是/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer /SDKs/iPhoneOS5.1.sdk/usr/lib

Done. 完成。 Launch xcode and chose GCC 4.2 in settings where necessary. 启动xcode并在必要时在设置中选择GCC 4.2。 You should delete the outdated "Developer" directory. 您应该删除过时的“Developer”目录。

Xcode should now also accept updates via Mac App Store again (this remains to be tested). Xcode现在也应该再次通过Mac App Store接受更新(这仍有待测试)。 I also did not download command line tools, but my guess is it will survive that too. 我也没有下载命令行工具,但我猜它也会存活下来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM