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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7765157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:07:22  来源:igfitidea点击:

Use gcc 4.2 in Xcode 4.2 and iOS SDK 5.0

iphoneiosxcodegcccompiler-construction

提问by Zhao Xiang

I just upgraded to Xcode 4.2 and iOS SDK 5 earlier today. But everything seems different with new compilers.

我今天早些时候刚刚升级到 Xcode 4.2 和 iOS SDK 5。但是对于新的编译器,一切似乎都不同了。

There are two "Compiler for C/C++/Objective-C" options now, "Apple LLVM compiler 3.0" and "LLVM GCC 4.2". GCC 4.2 is missing.

现在有两个“C/C++/Objective-C 编译器”选项,“Apple LLVM 编译器 3.0”和“LLVM GCC 4.2”。缺少 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. It looks like there's some differences on memory, and it crashes when loading our game's scripts.

Apple LLVM 编译器 3.0,构建速度非常快(我喜欢),给了我 999 多个警告,我的游戏无法再运行。看起来内存有一些差异,并且在加载我们的游戏脚本时会崩溃。

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? Is that even possible?

那么,这就引出了一个问题,我如何在 Xcode 4.2 中使用 gcc 4.2?这甚至可能吗?

采纳答案by chown

Here is a way to enable compiling with gcc 4.2in xcode 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 Terminaland run the command after the $.

这是一种在xcode 4.2 中启用gcc 4.2编译的方法。其中大部分是通过命令行完成的,因此当您看到这样的行时:,您需要打开终端并在.[ 15:30 jon@MacBookPro / ]$$

No files or directories are removedor deletedin this process, so it is easy to undo if you need to compile with LLVM in the future.

在此过程中不会移除删除任何文件或目录,因此如果您以后需要使用 LLVM 进行编译,很容易撤消。

  1. Download - but do notinstall yet- xcode_4.1_for_lion.dmgor xcode_4.1_for_snow_leopard.dmg

  2. Now, follow these steps to install Xcode 4.1 into /Developer-4.1:

    1. Backup the working /Developerdirectory (where Xcode 4.2 is installed)

    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)

    4. Move the new Xcode 4.1 installation to /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:

      [ 15:30 jon@MacBookPro / ]$ sudo mv -v /Developer-4.2 /Developer
      
  3. Edit the Xcode 4.2 GCC 4.2.xcspecfile to get gcc 4.2 to show in the list of compiler options [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 41and 42from this:

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

      ShowInCompilerSelectionPopup = YES; 
      IsNoLongerSupported = NO;
      
  4. Backup the Xcode 4.2 iOS/Simulator Framework usrdirectories:

    [ 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 usrdirectories to 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 gccand infoiOS SDK library directories from Xcode 4.1 to 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!

    Screenshot of CGG 4.2 in xcode 4.2

  1. 下载-但没有安装尚未- xcode_4.1_for_lion.dmgxcode_4.1_for_snow_leopard.dmg

  2. 现在,按照以下步骤将 Xcode 4.1 安装到/Developer-4.1

    1. 备份工作/Developer目录(安装 Xcode 4.2 的位置)

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

    4. 将新的 Xcode 4.1 安装移动到/Developer-4.1

      [ 15:30 jon@MacBookPro / ]$ sudo mv -v /Developer /Developer-4.1
      
    5. 将 Xcode 4.2 开发者目录移回/Developer

      [ 15:30 jon@MacBookPro / ]$ sudo mv -v /Developer-4.2 /Developer
      
  3. 编辑 Xcode 4.2GCC 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"
    
    • 将第4142行更改为:

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

      ShowInCompilerSelectionPopup = YES; 
      IsNoLongerSupported = NO;
      
  4. 备份 Xcode 4.2 iOS/Simulator Frameworkusr目录:

    [ 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. 将 Xcode 4.1 iOS/Simulator Frameworkusr目录复制到 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. 将Xcode 4.1gccinfoiOS SDK 库目录复制到 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. 使用 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 it/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/libdirectories but the iPhoneSimulator.platform SDK does not

[2]这是必要的,因为 iPhoneOS.platform SDK 有自己单独的/usr/lib目录,但 iPhoneSimulator.platform SDK 没有

回答by Auburg

In this years WWDC, Apple stated that GCC is no longer available in XCode 4.2. However, they stated that the LLVM compiler supports the same command line switches as GCC.

在今年的 WWDC 上,Apple 表示 GCC 在 XCode 4.2 中不再可用。但是,他们表示 LLVM 编译器支持与 GCC 相同的命令行开关。

回答by Thomas

I tried to update this for the applified version of Xcode. This will show how to install Xcode 4.4.x with full gcc support.

我试图为 Xcode 的应用版本更新它。这将展示如何安装具有完整 gcc 支持的 Xcode 4.4.x。

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. Download from Apple with your dev account. Don't install yet.

您需要:Lion 的 Xcode 4.1 副本。使用您的开发帐户从 Apple 下载。还不安装。

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 行和第 42 行。确保它们与此处显示的完全相同(这些值将在全新安装中颠倒)。

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"

现在 Lion 将尝试合并这两个目录。确保按“保持更新”

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. You should delete the outdated "Developer" directory.

完毕。启动 xcode 并在必要时在设置中选择 GCC 4.2。您应该删除过时的“Developer”目录。

Xcode should now also accept updates via Mac App Store again (this remains to be tested). I also did not download command line tools, but my guess is it will survive that too.

Xcode 现在也应该再次通过 Mac App Store 接受更新(这还有待测试)。我也没有下载命令行工具,但我猜它也能幸免于难。