56

How do you install clang-tidy on macOS?

It seems quite easy to install clang-format (using brew) on macOS, but it it seems much harder to install clang-tidy without install and building all of clang and building from source. Is there a better option?

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
Michael Reneer
  • 2,271
  • 1
  • 16
  • 22
  • 2
    I did not find one, some details here: https://embeddedartistry.com/blog/2017/2/20/installing-clangllvm-on-osx . `brew reinstall llvm --with-toolchain` : `/usr/local/Cellar/llvm/7.0.0: 5,351 files, 2.8GB, built in 50 minutes 39 seconds` . – Liviu Nov 08 '18 at 12:33
  • 1
    Thanks for the link, I expanded on the articles suggestions and added some background detail. – Michael Reneer Nov 19 '18 at 18:47

2 Answers2

86

I don't think there is a really easy way to do this today, here are some details:

  • clang comes installed on macOS and is the default compiler, but it does not come installed with clang-format or clang-tidy (or possibly any of the extra tools).
  • It's really easy to use brew to install clang-format if you want it: brew install clang-format
  • There is no clang-tidy brew formula.

As a result it seems like the best way to get clang-tidy on macOS is to simply install all of llvm and then make symlinks for the tools you want to use.

brew install llvm
ln -s "$(brew --prefix llvm)/bin/clang-format" "/usr/local/bin/clang-format"
ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy"
ln -s "$(brew --prefix llvm)/bin/clang-apply-replacements" "/usr/local/bin/clang-apply-replacements"

Alternatively, you could download the prebuilt binaries and create the same symlinks. It's not a good idea to add all of llvm to your PATH because of conflicts with the default clang compiler.

chrysante
  • 2,328
  • 4
  • 24
Michael Reneer
  • 2,271
  • 1
  • 16
  • 22
9

you can use brew install fmenezes/tap/clang-tidy today

  • I'm getting strange errors from this `clang-tidy`: `error: 'string' file not found [clang-diagnostic-error]` (complains about line `#include `). and I'm not getting such errors when running on linux – igagis Apr 15 '22 at 18:27
  • I think this does not work because it uses llvm 14 but current Mac xcode is still on 13.x so there are missing include headers – Connor Clark Jun 13 '22 at 08:48
  • 1
    Not found in 2023. – ynn Mar 26 '23 at 08:26