C++ 安装了 Xcode 命令行工具的 Mac OS X 中的 clang-format 和 clang-format.py 在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21151731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:30:10  来源:igfitidea点击:

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

c++macosclangclang-format

提问by Ahmed Fasih

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?

我在使用 Xcode 5 及其命令行工具的 Mac OS 10.8.5 上很难找到 clang-format 和 clang-format.py。我试过find / -name "clang-format.py"没有运气。他们已经在这里藏身,或者我如何获得这个工具链?

(I'm surprised it doesn't seem readily available since clang is Apple's compiler---in that Apple uses it.)

(我很惊讶它似乎不容易获得,因为 clang 是 Apple 的编译器——因为 Apple 使用它。)

回答by

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

似乎 Apple 没有随命令行工具一起提供clang-format。现在你至少有三个选择:

  • Using Homebrew(That's the way to go)
  • Using prebuild packages
  • Build it yourself
  • 使用Homebrew这就是要走的路
  • 使用预构建包
  • 自己搭建


Homebrew

家酿

As user johnhaley81pointed out, clang-formatis now in homebrew:

正如用户johnhaley81指出的,clang-format现在是自制软件

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

clang-format 现在在 brew 上。 brew install clang-format

Please consider upvoting his postif you find this answer useful.

如果您发现此答案有用,请考虑对他的帖子进行投票。



Prebuild packages

预构建包

Pre-build bundles are available at llvm.org. For Mac OSX, you need to download the darwinpackage.

预构建包可在llvm.org 获得。对于 Mac OSX,您需要下载darwin包。



Build instructions:

构建说明:

Here's an instruction on how to do this: http://nacho4d-nacho4d.blogspot.de/2013/11/clang-format.html

这是有关如何执行此操作的说明: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

这是另一个:http: //blog.hardcodes.de/articles/63/building-clang-format-and-friends-on-osx-mountain-lion

回答by johnhaley81

You can use brew now to install clang-format.

您现在可以使用 brew 来安装 clang-format。

brew install clang-format

brew install clang-format

回答by Gustavo Barcena

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.

我知道这不是问题的直接答案,但如果您只是想在 Xcode 中格式化代码。我刚用这个插件。

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

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

回答by Feu

Specific versions of clang-format

具体版本 clang-format

As of november/2018, current clang-formatformula on Homebrew points to version 8.0.0. Run clang-format --versionto check yours.

截至 2018 年 11 月,clang-formatHomebrew 上的当前公式指向 version 8.0.0。跑去clang-format --version检查你的。

If you need older versions of clang-format, consider following these steps:

如果您需要旧版本的clang-format,请考虑执行以下步骤:

Installing clang-format version 5 (5.0.2) with homebrew

使用自制软件安装 clang-format 版本 5 (5.0.2)

Installing clang-format version 7 (7.0.0) with homebrew

使用自制软件安装 clang-format 版本 7 (7.0.0)

回答by Alibek Taalaibek Uulu

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

就我而言,我使用 brew install 安装了 clang-format 并位于: /usr/local/bin/clang-format