I need to use gcc 4.2 with Xcode 4.2 for some older code. How do i get it to show up. Xcode4.2 seems to have dropped support for it.
Thanks
On
Thanks chown for sharing this! 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:
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!
Follow step 3 from the original description:
Edit the Xcode 4.2 GCC 4.2.xcspec file to get gcc 4.2 to show in the list of compiler options.
Make Xcode find the compiler again:
ln -s /usr/bin/gcc-4.2 /Developer/usr/bin/gcc-4.2
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!
On
So the full process for getting gcc 4.2 to work with a fresh install of Xcode 4.2 (non-iOS) is:
Install gcc 4.2
sudo port install apple-gcc42
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
I explained the problem and workaround in this blog post, which condenses the information I found. Feel free to comment.
On
Simple and userful solution https://github.com/kennethreitz/osx-gcc-installer/ It automates the lists of the declaration on the stackoverflow
Here is a way to enable compiling with gcc 4.2 in xcode 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$.Download - but do not install yet - xcode_4.1_for_lion.dmg or xcode_4.1_for_snow_leopard.dmg
Now, follow these steps to install Xcode 4.1 into
/Developer-4.1:Backup the working
/Developerdirectory (where Xcode 4.2 is installed)Run the Xcode 4.1 installer using the default install location (
/Developer)Move the new Xcode 4.1 installation to
/Developer-4.1:Move the Xcode 4.2 developer directory back to
/Developer:Edit the Xcode 4.2
GCC 4.2.xcspecfile to get gcc 4.2 to show in the list of compiler options [1]:Change lines 41 and 42 from this:
To This:
Backup the Xcode 4.2 iOS/Simulator Framework
usrdirectories:Copy Xcode 4.1 iOS/Simulator Framework
usrdirectories to Xcode 4.2:Copy the
gccandinfoiOS SDK library directories from Xcode 4.1 to Xcode 4.2 [2]:Compile using gcc-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[2] This is necessary because the iPhoneOS.platform SDK has its own seperate
/usr/libdirectories but the iPhoneSimulator.platform SDK does not