Getting gcc 4.2 to work with Xcode 4.2
Apparently, gcc 4.2 is no longer installed with Xcode (as of Xcode 4.2). Unfortunately, older projects may need to be compiled with gcc. There is some scattered information online about how to get gcc 4.2 with Xcode 4.2, but they seem complex and error-prone (e.g. install Xcode 4.1, then upgrade to 4.2).
UPDATE: Here are some situations you might find yourself in:
- Upgrading from Snow Leopard to Lion – it seems that gcc et al will be moved to a different location. See here for a fix.
- Upgrading to Xcode 4.2 – gcc 4.2 should still be on your machine; you just have to tell Xcode 4.2 to list it as an option (in which case, skip to step #2 below)
- Installing Xcode 4.2 with no previous version – no gcc 4.2 at all; follow instructions below.
Here’s an easy way to get gcc 4.2 working [1]:
1) Install gcc 4.2. via Mac Ports:
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:
- Open the xcspec file for editing:
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" |
- Change lines 41 and 42 from this:
ShowInCompilerSelectionPopup = NO;
IsNoLongerSupported = YES;
To This:
ShowInCompilerSelectionPopup = YES;
IsNoLongerSupported = NO;
- Link the gcc 4.2 binary to the location that Xcode expects
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 |
[1] Adapted from this Stack Overflow thread
Very interesting and well explained procedure: thanks for sharing!
Is such a trick valid for avr-gcc and pic32-gcc flavours also?
@Rei vilo I’m glad it helped! I don’t know anything about avr-gcc or pic32-gcc
Thanks!!!!