Reputation: 169
Is there any known way to get Xcode to work with GCC rather than clang or is this just a pipe dream and I should use a different IDE for such projects?
I'm using Xcode 7.3 beta and GCC 5.3.0.
Upvotes: 0
Views: 1560
Reputation: 23
I've updated the plugin for GCC 5.3 here:
https://github.com/JDeanThomas/xcode-gcc
You can change the default settings by showing the contents of the plugin and editing GCC 5.3.xcspec in /GCC 5.3.xcplugin/Contents/Resources
Add the GCC 5.3 plugin to: /Applications/Xcode.app/Contents/Plugins/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/
Open Xcode and open/create a project. Select the project and under Build Settings > Build Options > Compiler for C/C++/Objective-C you should see the option to select GCC 5.3.
One issue I ran into: You will need to edit:
"Clang LLVM 1.0.xcplugin" in /Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/Clang LLVM 1.0.xcplugin/Contents/Resources.
Under “Name = "CLANG_CXX_LIBRARY”” change “CommandLineArgs” and “AdditionalLinkerArgs” from "-stdlib=$(value)" to "-std=$(value)" so that when you enter your own value it passes -std= to the compier (GCC's standard) rather than -stdlib (Clang's standard). You will have to select a value (eg: "c++98", "gnu++98", "c++0x", "gnu++0x", "c++14", "gnu++14”), otherwise it will use “Compiler default,” which uses the -stdlib flag. You can edit the “Compiler Default” setting in the same entry, but if you attempt to use Clang in a compile, it will use -std rather than -stdlib, as expected by Clang.
In the entry above, “Name = "CLANG_CXX_LANGUAGE_STANDARD””, under “CommandLineArgs,” you should also change "gnu++14" = ( "-std=gnu++1y" ); to "gnu++14" = ( "-std=gnu++14” ); . gnu++1y is depreciated and gnu++14 (c++14 with GNU extensions) is now the default (as of GCC 6.1).
I just enter gnu++14 for target and build under Build Setings > User-Defined > CLANG_CXX_LIBRARY after making the above changes unless I need an older standard (i.e. c++11) for compatibility. If I need to use Clang, then I just leave the setting blank and it will revert to -stdlib using gnu++14 (Clangs default)
I will add a copy of the Clang plugin with the changes to the github repository above if you wish to backup your copy and drop the modified one in.
More on GCC settings here:
https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html
https://gcc.gnu.org/onlinedocs/gcc/Standards.html
Upvotes: 1