Add custom compiler to Xcode
Update 2013-11-13 Added paths for Xcode 4.2 and 3.6
I do a lot of my coding on osx, and was getting annoyed that I could not pick a specific compiler from within Xcode that I had installed. Using makefiles is an option but I wanted to see if I could add a new compiler to Xcode 4. This guide was the basis for mine, tweaked for Xcode 4
Xcode 4 and gcc-4.7 will be used as the example, in theory any compiler can be used (I have not tested this). This requires that you have installed gcc-4.7 from macports (usually gcc-mp-4.7)
Open up a terminal window (Root privileges will be required for some steps!) Go to you applications folder and open up the “Xcode.app” package.
For Xcode 4.2 the correct path is (thanks to Joram Vanhaerens for this info) stack overflow
For Xcode 3.6 the correct path is (untested)
Next create a copy of GCC 4.2.xcplugin and put it in the Xcode plugin path make the /Library/Application Support/Developer/Shared/Xcode/Plug-ins/ if it doesn’t already exist
sudo mkdir -p "/Library/Application Support/Developer/Shared/Xcode/Plug-ins/" sudo cp -r "GCC 4.2.xcplugin" "/Library/Application Support/Developer/Shared/Xcode/Plug-ins/GCC 4.7.xcplugin"
Navigate into package
cd "/Library/Application Support/Developer/Shared/Xcode/Plug-ins/GCC 4.7.xcplugin/Contents"
Next we need to convert the plist into xml as it is in binary so that we can edit it (if you’d prefer to use something other than vi, feel free)
sudo plutil -convert xml1 Info.plist sudo vi Info.plist
Make the following changes:
"com.apple.xcode.compilers.gcc.42" -> "com.apple.xcode.compilers.gcc.47" "GCC 4.2 Compiler Xcode Plug-in" -> "GCC 4.7 Compiler Xcode Plug-in"
Convert Info.plist back to binary
sudo plutil -convert binary1 Info.plist
In the “Resources” folder rename “GCC 4.2.xcspec” to “GCC 4.7.xcspec” In the “Englist.lproj” folder rename “GCC 4.2.strings” to “GCC 4.7.strings”
cd Resources/ sudo mv GCC\ 4.2.xcspec GCC\ 4.7.xcspec cd English.lproj/ sudo mv GCC\ 4.2.strings GCC\ 4.7.strings
Open the GCC 4.7.xcspec file and change, make sure to use sudo:
Identifier = "com.apple.compilers.gcc.4_7"; Name = "GCC 4.7"; Description = "GNU C/C++ Compiler 4.7"; Version = "4.7"; ExecPath = "gcc-mp-4.7"; ShowInCompilerSelectionPopup = YES; IsNoLongerSupported = NO;
Now, at this point the compiler should appear in Xcode (make sure to exit and open up Xcode again) but will probably error out due to some compiler flags which we need to fix
open up GCC 4.7.xcspec
under Name = "GCC_ENABLE_PASCAL_STRINGS"; set DefaultValue = NO; under Name = "GCC_CW_ASM_SYNTAX"; set DefaultValue = NO;
in your Xcode project under “Other Warning Flags” remove the -Wmost option
Compilation should now work!
Feel free to shoot me an email at [email protected] if you have suggestions on how to improve this guide.