How to install clang-format on MinGW (Windows)?

I tried searching with pacman -Ss for clang-format, git-clang-format, etc, but I'm not having any luck.

However, I have seen some references to it on some other websites, implying it may exist (or have existed) somewhere.

3 Answers

You can get it as part of the LLVM compiler build for Windows. You can download it from . Once installed, clang-format.exe can be found in C:\Program Files\LLVM\bin.

I know it's a bit heavy to install the whole compiler just to get the formatter, but yeah, it just feels safer compared to other sources, given that it's from LLVM itself.

Besides, the installer holds an archive that several tools (e.g. 7-Zip) can open. If you have downloaded the installer, but do not want to install the whole thing, extract the single executable from the archive under bin.

1

As utilities, clang-format and git-clang-format are available in several forms:

  • As a part of clang.

    [As noted by OP in the final comments below, and with OP's answer to their own question, these should be included with MSYS2/MingGW on Windows].

  • As pre-compiled Python wheels for Linux (only) available via pip (PyPI).

  • As modules available for Node.js. On Windows, use the standard Windows installer to install Node.js. Otherwise, example Linux package manager commands for installing Node.js are here.

Python

For Python versions on Linux, you may wish to try:

python3 -m pip install clang-format 

Node.js

Assuming Node.js is installed, you can also get them both with:

npm install -g clang-format

Note that on Windows, using the Node.js option seems to be the simplest solution for obtaining just clang-format and git-clang-format (without installing MinGW).


10

It turns out that MSYS2 already comes with clang installed, and clang comes with clang-format. As of my version of clang, I have clang-format 9.0.0 installed. it's possible much earlier versions of clang did not come with it installed.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like