Xcode 4中没有gcc 4.2编译器选项?

时间:2011-09-23 16:09:38

标签: iphone xcode xcode4 gcc4

在我的Xcode 4安装中,我只有2个编译器选项:

  1. Apple LLVM编译器3.0
  2. GCC LLVM 4.2
  3. 在许多Xcode示例中,我看到GCC 4.2显示为第三种选择,但这根本不存在。我故意干净安装XCode 4.是否有标准的方法来添加GCC 4.2,如果它还没有?我的一个项目要求我使用GCC(而不是GCC LLVM),其他项目我对GCC LLVM感到满意,所以这只是一个问题。

2 个答案:

答案 0 :(得分:6)

以下是在 xcode 4.2 中使用 gcc 4.2 进行编译的方法。这主要通过命令行完成,因此当您看到以[ 15:30 jon@MacBookPro / ]$开头的行时,您需要打开 Terminal.app 并运行在$之后启动的命令。

  

此过程中没有文件或目录被删除已删除,因此如果您将来需要使用LLVM进行编译,则很容易撤消。

  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.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"
    
    • 从此处更改 41 42 行:

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

      ShowInCompilerSelectionPopup = YES; 
      IsNoLongerSupported = NO;
      
  4. 备份Xcode 4.2 iOS /模拟器框架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. 将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. 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. 使用gcc-4.2进行编译!

    Screenshot of CGG 4.2 in xcode 4.2

  8. <强> 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] 如果从命令行打开(使用viemacsnano之类的东西等),请确保封闭路径在引号“/ long path / with spaces / in / file.xcspec”或转义空格 / some / long \ path / with \ spaces / in \ it / file.xcspec < / KBD>

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

答案 1 :(得分:0)

Xcode 4.3有一个特定的文件夹/Applications/Xcode.app/Contents/Developer/Toolchains

有没有办法将其他工具链添加为AVR-gcc和PIC32-gcc?