Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use clang-format from macports?

I would like to use clang-format, but I can't find it in my system. I have llvm installed from macports. What is the way to install/enable it?

like image 654
gruszczy Avatar asked Aug 21 '16 22:08

gruszczy


People also ask

How do I install clang formatter?

You can install clang-format and git-clang-format via npm install -g clang-format . To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows.

Where is clang-format install?

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.


1 Answers

First install clang-3.9 with MacPorts with the command

sudo port install clang-3.9

Afterwards, you will find clang-format-mp-3.9 in /opt/local/bin which should already be in your PATH so you can just use it.

If you want to make clang and all other related tools point to the version you just installed, you can use the select mechanism of MacPorts.

You can see all available choices with port select --list for clang.

$ port select --list clang
Available versions for clang:
    mp-clang-3.8
    mp-clang-3.9
    none (active)

With sudo port select --set clang <version> you choose one of them as the new default, which will create symlinks in /opt/local/bin without the version suffix.

$ sudo port select --set clang mp-clang-3.9
Selecting 'mp-clang-3.9' for 'clang' succeeded. 'mp-clang-3.9' is now active.

You can confirm this change by looking at the version of the tool:

$ clang-format --version
clang-format version 3.9.0 (tags/RELEASE_390/final)

If you later wish to remove these symlinks in order to avoid hiding tools installed by Xcode, just select the none version.

like image 70
raimue Avatar answered Jan 03 '23 18:01

raimue