简体   繁体   English

如何在Xcode 4.2中使用gcc 4.2

[英]How to use gcc 4.2 with Xcode 4.2

I need to use gcc 4.2 with Xcode 4.2 for some older code. 对于一些较旧的代码,我需要使用带有Xcode 4.2的gcc 4.2。 How do i get it to show up. 我如何让它出现。 Xcode4.2 seems to have dropped support for it. Xcode4.2似乎已经放弃了对它的支持。

Thanks 谢谢

Here is a way to enable compiling with gcc 4.2 in xcode 4.2 . 这是一种在xcode 4.2中使用gcc 4.2进行编译的方法。 This is mostly done via command line so when you see lines starting with: [ 15:30 jon@MacBookPro / ]$ , you need to open up Terminal.app and run the command that starts after the $ . 这主要通过命令行完成,因此当您看到以[ 15:30 jon@MacBookPro / ]$开头的行时,您需要打开Terminal.app并运行在$后面开始的命令。

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没有

Thanks chown for sharing this! 感谢chown分享这个! I struggled around half a day, but at the end it turned out, that I only needed a few steps to achieve my goal: 我挣扎了大约半天,但结果却发现,我只需要几个步骤来实现我的目标:

For everyone that just needs GCC-4.2 to compile apps (no iOS stuff) it's pretty easy: You don't need to install anything just follow these few steps: 对于每个只需要GCC-4.2来编译应用程序 (没有iOS内容)的人来说,这很简单:只需按照以下几个步骤安装即可:

  1. EDIT: If you don't have GCC 4.2 installed already (from an earlier version of Xcode, or manual install), follow the instruciotns from Sean DeNigris in the comments! 编辑:如果您尚未安装GCC 4.2(从早期版本的Xcode或手动安装),请在评论中按照Sean DeNigris的说明进行操作!

  2. Follow step 3 from the original description: 按照原始描述中的步骤3进行操作:
    Edit the Xcode 4.2 GCC 4.2.xcspec file to get gcc 4.2 to show in the list of compiler options. 编辑Xcode 4.2 GCC 4.2.xcspec文件,使gcc 4.2显示在编译器选项列表中。

  3. Make Xcode find the compiler again: 让Xcode再次找到编译器:

    ln -s /usr/bin/gcc-4.2 /Developer/usr/bin/gcc-4.2

  4. Also make the linker available: 还可以使链接器可用:

    ln -s /usr/bin/g++-4.2 /Developer/usr/bin/g++-4.2

This works perfectly for me! 这对我来说非常合适! But as I said it's just for non iOS products! 但正如我所说,这只适用于非iOS产品!

So the full process for getting gcc 4.2 to work with a fresh install of Xcode 4.2 (non-iOS) is: 因此,使用全新安装的Xcode 4.2(非iOS)来获取gcc 4.2的完整过程是:

  1. Install gcc 4.2 安装gcc 4.2

     sudo port install apple-gcc42 
  2. Tweak Xcode so that gcc 4.2 appears as a compiler option, by editing the Xcode 4.2 GCC 4.2.xcspec file to get gcc 4.2 to show in the list of compiler options: 调整Xcode以使gcc 4.2作为编译器选项出现,通过编辑Xcode 4.2 GCC 4.2.xcspec文件获得gcc 4.2以显示在编译器选项列表中:

    1. Open the xcspec file for editing: 打开xcspec文件进行编辑:

       sudo vi "/Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/GCC 4.2.xcplugin/Contents/Resources/GCC 4.2.xcspec" 
    2. Change lines 41 and 42 from this: 从这里改变第41和42行:

       ShowInCompilerSelectionPopup = NO; IsNoLongerSupported = YES; 

      To This: 对此:

       ShowInCompilerSelectionPopup = YES; IsNoLongerSupported = NO; 
  3. Link the gcc 4.2 binary to the location that Xcode expects: 将gcc 4.2二进制文件链接到Xcode期望的位置:

     sudo ln -s /opt/local/bin/gcc-apple-4.2 /Developer/usr/bin/gcc-4.2 sudo ln -s /opt/local/bin/g++-apple-4.2 /Developer/usr/bin/g++-4.2 

I explained the problem and workaround in this blog post , which condenses the information I found. 我在这篇博文中解释了问题和解决方法,它浓缩了我发现的信息。 Feel free to comment. 随意评论。

简单且用户友好的解决方案https://github.com/kennethreitz/osx-gcc-installer/它自动化stackoverflow上的声明列表

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

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