为什么clang-format仅格式化.c或.h文件,但不是两个? 我正在使用VS代码中的Clang-Format在MacOS上格式化我的C代码,但是我遇到了一个奇怪的问题: 我有以下.clang-Format配置: 语言:c 基础态度:Google 和我的VS代码

问题描述 投票:0回答:1
.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
位于
c++ c macos visual-studio-code clang-format
1个回答
0
投票
。 由于某种原因,此版本的

brew install clang-format

在格式化
/opt/homebrew/bin/clang-format

clang-format

文件方面存在问题。
要解决此问题,而是通过LLVM使用

.c

.h

,然后更新新安装版本的
clang-format
路径:
brew install llvm
这解决了问题。
	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.