gpt4 book ai didi

clang-tidy - 使用 clang-tidy 和compile-commands.json 来解析多个文件

转载 作者:行者123 更新时间:2023-12-03 07:58:23 44 4
gpt4 key购买 nike

我无法让 clang-tidy 读取我的编译数据库。如果我尝试:

clang-tidy --config-file ./.clang-tidy -checks=* -p ./target

clang-tidy --config-file ./.clang-tidy -checks=* -p ./target/compile-commands.json

我明白了

Error: no input files specified.
USAGE: clang-tidy [options] <source0> [... <sourceN>]
...

但是根据--help -p 是指定它的路径的方式。只有当我指定单个文件时,它似乎才起作用:

clang-tidy --config-file ./.clang-tidy -checks=* path/to/file.cpp

最佳答案

当你说“根据--help -p是指定它的路径的方式”时,我认为你指的是Clang-Tidy中的这段话页面:

-p <build-path> is used to read a compile command database.

For example, it can be a CMake build directory in which a file named
compile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
CMake option to get this output). When no build path is specified,
a search for compile_commands.json will be attempted through all
parent paths of the first input file . See:
https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an
example of setting up Clang Tooling on a source tree.

正如上面所说,-p 帮助 clang-tidy 找到 compilation database ,它告诉clang-tidy如何编译列出的源文件,但它实际上并没有指定要分析哪些文件。 (一般来说,数据库可以说明如何编译很多东西,但您可能只想分析其中的一个子集。)

要指定要分析的内容,您必须在命令行上的选项后面列出所有文件名。也许不幸的是,没有办法让 clang-tidy 分析编译数据库中的所有内容。

关于clang-tidy - 使用 clang-tidy 和compile-commands.json 来解析多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75330301/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com