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

3
在我的Xcode 4安装中,我只有两个编译器选项:
  1. Apple LLVM编译器3.0
  2. GCC LLVM 4.2
在许多Xcode示例中,我看到GCC 4.2被显示为第三个选项,但实际上并不存在。我有意进行了干净的XCode 4安装。如果没有GCC 4.2,是否有添加它的标准方法?我的一个项目需要使用GCC(而不是GCC LLVM),其他项目我很满意使用GCC LLVM,所以这只是针对那一个项目的问题。

感谢 @Bavarious,这正是正确的答案。问题还为时过早。 - MOK9
2个回答

6
以下是使用gcc 4.2xcode 4.2中进行编译的方法。大部分操作都是通过命令行完成的,所以当您看到以[ 15:30 jon@MacBookPro / ]$开头的行时,需要打开Terminal.app并运行以$开始的命令。

在此过程中不会删除任何文件或目录,因此如果将来需要使用LLVM进行编译,则可以轻松撤销。

  1. Download - but do not install yet - xcode_4.1_for_lion.dmg or 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 /Developer directory (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
    
  • Edit the Xcode 4.2 GCC 4.2.xcspec file 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 41 and 42 from this:

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

      ShowInCompilerSelectionPopup = YES; 
      IsNoLongerSupported = NO;
      
  • Backup the Xcode 4.2 iOS/Simulator Framework usr directories:

    [ 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
    
  • Copy Xcode 4.1 iOS/Simulator Framework usr directories 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
    
  • Copy the gcc and info iOS 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
    
  • 使用gcc-4.2进行编译!

    CGG 4.2在xcode 4.2中的屏幕截图

  • 这是我撰写的一篇博客文章,更详细地介绍了这个过程。如果遇到任何问题或有任何疑问,请随时在博客上留言。


    [1] 如果从命令行打开(使用类似viemacsnano等),请确保将路径用引号括起来"/long path/with spaces/in it/file.xcspec",或转义空格/some/long\ path/with\ spaces/in\ it/file.xcspec

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


    0

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

    是否有办法添加其他的工具链,比如AVR-gcc和PIC32-gcc?


    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,