How to force Xcode to use an alternative version of clang?

How can I configure Xcode to use clang distributed by llvm.org instead of the one sent by Apple?

If I load clang binaries and install on /usr/local and then install my compiler Other .../usr/local/bin/clang in Xcode, then I get form errors:

Unsupported compiler '/ usr / local / bin / clang' selected for architecture 'x86_64'

Unable to determine specific GCC compiler for file ... of type sourcecode.cc

UPDATE:. I found a way to make this work by symlinking /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr to the root directory clang+llvm-3.4-x86_64-apple-darwin10.9 , but it would be much better if there would be a way to install an alternative compiler for Xcode without changing the Xcode directory tree.

+6
source share
2 answers

The easiest option (also the easiest to change) is to add the CC build flag. Go to the settings of the project or the target assembly and select "Editor" → "Add build settings" → "Add custom settings" in the menu.

Adding custom build flags

Name the CC flag and set the value for the path to your Clang binary.

Setting the <code> CC </code> flag

You can choose whether you want to use this compiler for all assemblies or just debug assemblies (this makes sense, for example, when using experimental and / or self-modified versions of Clang).

Please note that for functions such as autocomplete, symbolic search, etc., Xcode does not use the Clang binary libraries, as well as other LLVM libraries distributed with Xcode. I described how to replace the ones that are in another post (this is more or less the same approach that you took). By changing only the Clang version, you may receive different warnings after compilation than those that appear in the editor as you type.

+10
source

His old question, but since I wanted to install a later clang / libC ++ for use with Xcode 9+, here is my solution in the hope that it will be useful for someone.

  • If you are building source code, be sure to pass -DLLVM_CREATE_XCODE_TOOLCHAIN=ON to cmake, then run make install-xcode-toolchain. If you are installing using homebrew, use brew install --with-toolchain llvm
  • Copy the toolchain folder from any of its installed (/ usr / local / Toolchains) to / Library / Developer / Toolchains
  • Restart Xcode, you will see the Toolchains option in the Xcode menu.

A particular problem that I am facing is that clang complains about "cannot use the -o option with multiple output files." This was due to the fact that at the time of writing this Apple clang there was a new option that is not in the trunk. To fix this, disable the Index-While-Building function in the project settings.

+2
source

All Articles