Where are clang-format and clang-format.py in Mac OS X with Xcode Command Line Tools installed?
C++MacosClangClang FormatC++ Problem Overview
I am having a hard time finding clang-format and clang-format.py on my Mac OS 10.8.5 with Xcode 5 and its Command Line Tools. I tried find / -name "clang-format.py"
without luck. Are they already here somewhere hiding, or how would I get this toolchain?
(I'm surprised it doesn't seem readily available since clang is Apple's compiler---in that Apple uses it.)
C++ Solutions
Solution 1 - C++
Seems like Apple doesn't ship [clang-format][1] with the Command Line Tools. Right now you have at least three options:
- Using [Homebrew][2] (That's the way to go)
- Using prebuild packages
- Build it yourself
Homebrew
As user [johnhaley81][3] pointed out, clang-format
is now in [homebrew][2]:
> clang-format is now on brew. brew install clang-format
Please consider upvoting his [post][4] if you find this answer useful.
Prebuild packages
Pre-build bundles are available at [llvm.org][5]. For Mac OSX, you need to download the darwin package.
Build instructions:
Here's an instruction on how to do this: http://nacho4d-nacho4d.blogspot.de/2013/11/clang-format.html
And here's another one: http://blog.hardcodes.de/articles/63/building-clang-format-and-friends-on-osx-mountain-lion
[1]: http://clang.llvm.org/docs/ClangFormat.html "clang-format" [2]: http://brew.sh/ [3]: https://stackoverflow.com/users/560726/johnhaley81 "johnhaley81" [4]: https://stackoverflow.com/a/28325546/289841 "post" [5]: http://llvm.org/releases/download.html "llvm.org"
Solution 2 - C++
You can use brew now to install clang-format.
brew install clang-format
Solution 3 - C++
I know this is not a direct answer to the question but if you are just looking to format your code in Xcode. I just used this plug in.
Solution 4 - C++
clang-format
Specific versions of As of november/2018, current clang-format
formula on Homebrew points to version 8.0.0
. Run clang-format --version
to check yours.
If you need older versions of clang-format
, consider following these steps:
Solution 5 - C++
In my case I installed clang-format with brew install and located here: /usr/local/bin/clang-format
Solution 6 - C++
If you have the llvm
toolchain already installed, you can find the clang-format.py
file in /usr/local/opt/llvm/share/clang/clang-format.py
without having to install a separate clang-format
binary through Homebrew.