开发者

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. 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". GCC 4.2 is missing.

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.

LLVM GCC 4.2 is so god damn slow, I still cannot finish one build after hours on my i7 machine.

And, one more thing is our engine uses gcc command lines to build(instead of xcode).

So, it leads to one question, how can I use gcc 4.2 in Xcode 4.2? Is that even possible?


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

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.

  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
      
  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]:

    [ 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;
      
  4. 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
    
  5. 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
    
  6. 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
    
  7. Compile using gcc-4.2!

    Use gcc 4.2 in Xcode 4.2 and iOS SDK 5.0


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

[2] This is necessary because the iPhoneOS.platform SDK has its own seperate /usr/lib directories but the iPhoneSimulator.platform SDK does not


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.


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.

You need: Mac OSX Lion - this is important, don't try with Mountain Lion!

You need: a copy of Xcode 4.1 for Lion. Download from Apple with your dev account. Don't install yet.

Now install Xcode 4.4.x from Apple via Mac App Store.

After this is done, you will have xcode 4.4.x in your applications directory.

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).

Open Xcode 4.4.x via right mouse click and "Show Package Contents" and then navigate to the gcc 4.2 plugin here:

/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.

Look at lines 41and 42. Make sure they look exactly as presented here (the values will be reversed in a fresh install).

ShowInCompilerSelectionPopup = YES;
IsNoLongerSupported = NO;

Save and close.

Install Xcode 4.1 for Lion.

Now navigate to the developer directory at the root of your boot drive.

Navigate to /Developer/Platforms/iPhoneOS.platform/Developer/usr/

copy the usr directory with command-c

switch back to xcode 4.4.x

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

paste the usr directory with command-v

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

Again, merge and "Keep Newer"

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

Now copy the gcc directory by selecting it and using command-c

Navigate into the Xcode 4.4.x app:

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

Paste the gcc directory with command-v

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

Done. Launch xcode and chose GCC 4.2 in settings where necessary. You should delete the outdated "Developer" directory.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜