I want to force Xcode to use a custom compiler ('clang-llvm' build from the src) so I can use the clang plugin. My Xcode version is 7.3.1.
5 Answers
People say it is possible with custom toolchains. I didn't make a research on them because easier solution worked well for me:
It is also possible to run frontend plugins directly by setting appropriate "build settings" of Xcode. (Several ways to do this, you can set them on the command line for instance: xcodebuild build FOO=bla.) Here are a few build settings that I found useful to inject C flags:
OTHER_CFLAGS, OTHER_CPLUSPLUSFLAGS or to replace the compiler(s) and linker(s):
CC, CPLUSPLUS, LD, LDPLUSPLUS, LIBTOOL
The same approach works to control the "analyze" action: CLANG_ANALYZER_EXEC, CLANG_ANALYZER_OTHER_FLAGS
Disclaimer: some of those build settings are undocumented (afaik). Use at your own risk.
(Taken from [cfe-dev] Compile/refactor iOS Xcode projects)
For me it was enough to define the following User-Defined Settings in Build Settings of Xcode projects:
CC=my-c-compiler
CXX=my-cxx-compiler
LIBTOOL=my-linker-for-static-libraries
If you use CMake, the way to inject your compiler automatically is to use
set_target_properties(your-target PROPERTIES XCODE_ATTRIBUTE_CC "${YOUR_CC}")
set_target_properties(your-target PROPERTIES XCODE_ATTRIBUTE_CXX "${YOUR_CXX}")

- 1
- 1

- 11,044
- 8
- 69
- 129
Couple of years ago I've written an article that addresses exactly the problem you describe: Creating and using Clang plugin with Xcode
To enable custom clang you need to actually patch internals of Xcode.app
itself, it is technically doable but:
- it will break when you update Xcode
- it will work correctly on your machine
- the version of a plugin and your compiler should match, i.e. they should be compiled using the same tree
So in general it doesn't really scale, so be careful :)

- 4,022
- 25
- 31
There's a somewhat obscure feature of Xcode where it supports "alternative toolchains". For example, Swift.org provides installable toolchains for Swift built from current sources.
Unfortunately, while Apple's documentation describes how to install and use such alternative toolchains, it doesn't describe how to create them. There are scripts in the Swift source base which build a toolchain and you can look at them to figure out how it's done. They are in https://github.com/apple/swift/tree/master/utils. Start at build-toolchain, which calls build-script and go from there.

- 88,520
- 7
- 116
- 154
-
3LLVM can create a toolchain with the option `LLVM_CREATE_XCODE_TOOLCHAIN` https://stackoverflow.com/questions/63688639/c20-library-support-for-xcode-12#63688639 – Sep 22 '20 at 13:38
Method 1: Change the User Defined settings
Under the project or target Build Settings add the User Defined settings for
CC=/path/to/cc
CXX=/path/to/c++
This is useful if you have a single compiler or linker you want to call, or if you want to call out to a trampoline that decides what to call on the fly.
Method 2: Create a complete custom toolchain via plugin
Using Clang LLVM 1.0.xcplugin
as a template (found in the Xcode.app
plugins folder), you can modify the plist to point at your own alternative compiler and linker.
This OLLVM on iOS tutorial walks through it.

- 21,528
- 7
- 125
- 126
From project setting
go to build setting
with target selected. then select All
beside the Basic
from the top bar. then under build option you can see the compiler option.
Refer below screenshot,
Update :
I think you should refer Using C and C++ in an iOS App with Objective-C++ and this tutorial.

- 27,092
- 9
- 50
- 75
-
1when i add the compiler to this option, it show me that it is an unsupported compiler. – 许金龙 Sep 05 '16 at 11:47
-
with latest xcode you can only use `llvm` only. and why you want to set another one ? – Ketan Parmar Sep 05 '16 at 11:54
-
i want to use the clang plugin to get some function call information,it seems that the default compiler do not support plugin. – 许金龙 Sep 05 '16 at 12:16