Apple completely removed whatever GCC support they used to have. Is there any way to use a recent GCC (say 4.8) with Xcode 5? In other words, to use GCC in place of LLVM within Xcode.
2 Answers
install GCC 4.8 into Xcode 4.5, Xcode 4.6, Xcode 5.0:
for people who have not install GCC 4.8:
install the new version of home-brew
you can find the method how to install on the Internet
update your brew to the latest version ($brew update
)
1.brew install gcc48 --enable-all-languages
(may should install mpc, mpfr and gmp through brew, http://solarianprogrammer.com/2013/06/11/compiling-gcc-mac-os-x/)
2.$brew link gcc48
3.backup g++,gpp,c++,cpp,c++ in /usr/bin/
4.[optional step]:
alias g++-4.8,gpp-4.8,c++-4.8,cpp-4.8,c++-4.8
from /usr/local/Cellar/gcc48/4.8.2/bin/g++
to /usr/bin/
[above 4 steps for the developer who have not install gcc]
5.make plugin
1)download a plugin of GCC 4.5 for Xcode
2)change every "4.5" to "4.8", "4_5" to "4_8", the file names, the file contents,
except "com.apple.compilers.gcc.headers.4_2” in the file GCC 4.5.xcspec
.
you can remain contents in English.lproj
unchanged, and delete Japanese.lproj
.
3)in file GCC 4.8.xcspec
(hope you have already change the file name of GCC 4.5.xcspec
to GCC 4.8.xcspec
)
change ExecPath = "...”;
to ExecPath = "/usr/local/bin/gcc-4.8"
or ExecPath = "/usr/local/Cellar/gcc48/4.8.2/bin/gcc-4.8"
(for the people who install gcc-4.8 by brew)
4)delete “-Wshorten-64-to-32” part in file GCC 4.8.xcspec
{
Name = "GCC_WARN_64_TO_32_BIT_CONVERSION";
Type = Boolean;
DefaultValue = NO;
CommandLineArgs = {
YES = (
"-Wshorten-64-to-32",
);
NO = ();
};
AppearsAfter = "GCC_WARN_PROTOTYPE_CONVERSION";
Category = Warnings;
CommonOption = NO;
DisplayName = "Implicit Conversion to 32 Bit Type";
Description = "Warn if a value is implicitly converted from a 64 bit type to a 32 bit type.
[GCC_WARN_64_TO_32_BIT_CONVERSION, -Wshorten-64-to-32]";
}
6.put edited GCC 4.8.xcplugin
into
/Applications/Xcode.app/Contents/Plugins/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/
7.reopen Xcode.
Now, the new plugin has already prepared for you. You can see your new GCC compiler plugin in the "Compiler for C/C++/Objective-C" of "Build Settings" of your project
8.change Build Settings in Xcode project
1)In the project
and target
settings in Xcode
change "Compiler for C/C++/Objective-C" to "GCC 4.8"
2)In the project
settings
delete “CLANG_CXX_LIBRARY" row
-
In addition to this, I had to make sure my binaries would link against the libstdc++ libraries in /usr/local/Cellar/gcc48/4.8.2/gcc/lib, i.e., I had to set the library path for the linker with -L /usr/local/Cellar/gcc48/4.8.2/gcc/lib instead of -L /usr/lib. Oct 24, 2013 at 22:29
-
I tried this on XCode 5.0.2 and the GCC 4.8.2 compiler is not shown in the list of compilers. I also tried it with XCode 3 and it did show up there. Maybe XCode 5.0.2 broke something.– HaltFeb 13, 2014 at 21:37
-
@Halt, for me GCC shows up in the list of compilers. However I get an error about the "-Wmost" flag which is Clang this, but I cannot get rid of it– sisisMar 5, 2014 at 13:46
-
-
@frogcjn In XCode 5.1 you get a warning indicating 'Invalid C/C++' compiler in target followed by many errors reading Unsupported compiler '4.8' selected for architecture. Have tried adding <key>DVTPlugInCompatibilityUUIDs</key> <string>A2E4D43F-41F4-4FB9-BB94-7177011C9AED</string> to the plug-in's Info.plist to no avail.– rwbutlerApr 4, 2014 at 14:20
I'm pretty sure the latest versions of gcc can link against Apple's libraries. You can install newer versions of gcc, llvm (and clang), and a lot of other unix applications with Homebrew. Check it out here.
CC
flag in Xcode, as described under (2) in this post. The problem is that GCC has a different interface than Clang, so it doesn't understand all the flags Xcode sets by default. I couldn't make it work for an iOS template app, but it may work if you don't use a template or no Objective-C at all.