c++ - 如何在 Windows 上使用和配置 clang-tidy?

标签 c++ clang clang-tidy

我正在尝试使用 clang-tidy 代码分析,以便检查 CppCoreGuidelines。我为 Win 7 64 位下载了 LLVM 7.0.0 预构建二进制文件。我能够用 clang 成功编译,我做了一个编译这段代码的基本示例,我将源代码命名为 test.cpp:

// test.cpp
#include <iostream>

int main(int argc, char const *argv[])
{
    std::cout << "Hello World!" << std::endl;
    return 0;
}

然后我在终端中运行了这个:

clang test.cpp

我在编译时得到了这个输出:

test-c4b051.o : warning LNK4217: locally defined symbol __std_terminate imported in function "int `public: static unsigned __int64 __cdecl std::char_traits<char>::length(char const * const)'::`1'::dtor$2" (?dtor$2@?0??length@?$char_traits@D@std@@SA_KQEBD@Z@4HA)
test-c4b051.o : warning LNK4217: locally defined symbol _CxxThrowException imported in function "public: void __cdecl std::ios_base::clear(int,bool)" (?clear@ios_base@std@@QEAAXH_N@Z)

但是打印“Hello World”效果很好,直到这里一切正常,但是当我想运行 clang-tidy 时,我在运行它时得到以下输出,我从这里获取了引用 Extra Clang Tools 8 documentation :

clang-tidy test.cpp -checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus*



Error while trying to load a compilation database:
Could not auto-detect compilation database for file "test.cpp"
No compilation database found in C:\Users\uidr8361\Desktop\C++ or any parent directory
fixed-compilation-database: Error while opening fixed database: no such file or directory
json-compilation-database: Error while opening JSON database: no such file or directory
Running without flags.

我读过这个帖子,但这似乎适用于 clang 编译,我不知道这是否也适用于 clang 额外工具,尤其是 clang-tidy: How to compile Clang on Windows

最佳答案

只需在命令行末尾加上--(减去负号)

clang-tidy -checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus* test.cpp --

你通常会在之后放置你的 cl、gcc、clang 参数

clang-tidy -checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus* test.cpp -- -DDEBUG -I./include

关于c++ - 如何在 Windows 上使用和配置 clang-tidy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52710180/

相关文章:

debugging - 使用 clang 编译到 wasm 时如何保留变量名称

c - 为什么在macOS上用clang -O2编译C程序会出现 "empty"循环导致总线错误?

c++ - Clang 与 Clang tidy 是否检测到相同的警告和错误?

clang-tidy:分析有多个错误的文件

c++ - 使用 ORB 描述符训练 svm?

c++ - 如何避免到处链接某个目标文件

c - 双向链接中的用户输入

c++ - 带模板的 dllexport 函数 (C++)

c++ - 错误 : forward declaration of ‘class SActionPrivate’ when using PIMPL

boost - 使用 clang-tidy 处理大量与 boost 单元测试相关的警告