Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are clang-format and clang-format.py in Mac OS X with Xcode Command Line Tools installed?

People also ask

Where is clang-format py Mac?

clang-format is located in clang/tools/clang-format and can be used to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.

Where is clang-format file?

Configuring Style with clang-format When using -style=file, clang-format for each input file will try to find the . clang-format file located in the closest parent directory of the input file. When the standard input is used, the search is started from the current directory.


Seems like Apple doesn't ship clang-format with the Command Line Tools. Right now you have at least three options:

  • Using Homebrew (That's the way to go)
  • Using prebuild packages
  • Build it yourself

Homebrew

As user johnhaley81 pointed out, clang-format is now in homebrew:

clang-format is now on brew. brew install clang-format

Please consider upvoting his post if you find this answer useful.


Prebuild packages

Pre-build bundles are available at llvm.org. 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


You can use brew now to install clang-format.

brew install clang-format


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.

https://github.com/travisjeffery/ClangFormat-Xcode


Specific versions of clang-format

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:

Installing clang-format version 5 (5.0.2) with homebrew

Installing clang-format version 7 (7.0.0) with homebrew


In my case I installed clang-format with brew install and located here: /usr/local/bin/clang-format