如何指定c格式的文件? [英] How do I specify a clang-format file?

查看:178
本文介绍了如何指定c格式的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Redhat 6机器上构建了clang 5.0.0,并尝试运行clang格式。我无法使用-style选项来读取样式文件。这是我认为应该可以使用的一组命令的示例:

I just built clang 5.0.0 on a Redhat 6 machine and tried to run clang-format. I'm unable to get the -style option to read in a style file. Here's an example of a set of commands that I think should work:

./clang-format -style=llvm -dump-config > .llvm-format
./clang-format -style=.llvm-format ~/myFile.cc

运行此命令时,出现以下错误:

When I run this command I get the following error:

Invalid value for -style

当按预期放置在父目录中时,似乎可以找到并使用.clang格式。内置类型也可以使用:

It appears to find and use .clang-format when placed in a parent directory as expect. The built-in types also work:

./clang-format -style=Mozilla ~/myFile.cc

那么,问题是我无法明确指定要使用的.clang格式文件。这是我的构建是否有问题,还是我误用了clang格式的文档?

The problem, then, is that I can't specify explicitly a .clang-format file to use. Is this a problem with my build or am I misusing clang-format oir misunderstanding the documentation?

推荐答案

我也对此感到困惑。当他们告诉您使用标志 -style = file 时,它们的字面意思是您键入 -style = file ,而不是 -style =< path / to / actual / filename>

I got confused by that too. When they tell you to use the flag -style=file they literally mean for you to type out -style=file, NOT -style=<path/to/actual/filename>.

使用此标志, clang格式将查找名为的文件。格式在目标文件的目录中。如果找不到任何内容,则会显示 cd .. 并重试。似乎没有办法告诉 clang-format 使用未完全命名为 .clang-format

With this flag, clang-format will look for a file called .clang-format in the directory of the target file. If it doesn't find any it will cd .. and try again. There doesn't seem to be a way to tell clang-format to use a file that is not named exactly .clang-format.

您的示例的正确用法是:

The correct usage for your example would be:

./clang-format -style=llvm -dump-config > ~/.clang-format
./clang-format -style=file ~/myFile.cc

这篇关于如何指定c格式的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆