.clang-format
配置:
Language: C
BasedOnStyle: Google
我的VS代码clang-Format配置如下:
VS代码clang-Format配置
i可以毫无问题地格式化.c文件,但是,格式化.h文件会导致此错误:
Formatting failed:
/opt/homebrew/bin/clang-format --style=file:/Users/nov4ou/.clang-format --fallback-style=LLVM --Wno-error=unknown --assume-filename=/Users/nov4ou/Documents/EECS/UNIX-Programming/Project/include/get_num.h /Users/nov4ou/Documents/EECS/UNIX-Programming/Project/include/get_num.h
Error reading /Users/nov4ou/.clang-format: Unsuitable
i修改了
.clang-format
文件,将
Language
更改为
Cpp
:
:
Language: Cpp
BasedOnStyle: Google
this解决了.h
文件格式问题,但引入了相同的错误文件。
.c
经过一些研究,我发现没有相关信息。我不确定这是MacOS还是Clang-Format本身的问题。
I还测试了Linux上的
Formatting failed:
/opt/homebrew/bin/clang-format --style=file:/Users/nov4ou/.clang-format --fallback-style=LLVM --Wno-error=unknown --assume-filename=/Users/nov4ou/Documents/EECS/UNIX-Programming/Project/src/error_functions.c /Users/nov4ou/Documents/EECS/UNIX-Programming/Project/src/error_functions.c
Error reading /Users/nov4ou/.clang-format: Unsuitable
。当我设置clang-format
时,它可以很好地适用于Language: Cpp
和
.c
文件。
我正在使用的comoiler:
.h
经过一些试验,我发现了问题的原因:通过Homebrew.安装的版本。
通过啤酒安装的
$ gcc --version
Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: arm64-apple-darwin24.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
:
clang-format
位于brew install clang-format
在格式化
/opt/homebrew/bin/clang-format
和clang-format
文件方面存在问题。要解决此问题,而是通过LLVM使用
.c
:
.h
clang-format
路径:brew install llvm
这解决了问题。