How can I set up Xcode up to use the clang distributed by llvm.org instead of the one shipped by Apple?
If I download the clang binaries and install to /usr/loc
Its an old question, but since I wanted to install more recent clang/libc++ to use with Xcode 9+, here is my solution in hope it would be useful for someone.
-DLLVM_CREATE_XCODE_TOOLCHAIN=ON
to cmake, afterwards run make install-xcode-toolchain. If you install with homebrew, use the brew install --with-toolchain llvm
A particular issue I run into is that clang complains about "can't use -o option with multiple output files". This was because at the time of writing this Apple's clang has a new option that was missing in trunk. To fix this, disable the Index-While-Building
function in your project settings.
The easiest option (also the easiest to reverse) is to add the CC
build flag. Go to your project's or target's build settings, and choose Editor --> Add Build Setting --> Add User-Defined Setting from the menu.
Name the flag CC
, and set the value to the path to your Clang binary.
You can choose whether you want to use this compiler for all builds, or just debug builds (this makes sense when you use experimental and/or self-modified versions of Clang, for instance).
Note that for features like autocompletion, symbolic search etc., Xcode does not use the Clang binary but other LLVM libraries distributed with Xcode. I've described how to replace those in another post (which is more or less the same approach that you took). By only changing the Clang version, you may get different warnings after compiling than those shown in the editor while typing.