Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use and configure clang-tidy on windows?

I'm trying to use clang-tidy code analysis so I can check for CppCoreGuidelines. I downloaded LLVM 7.0.0 pre-built binary for Win 7 64 bits. I'm able to successfully compile with clang, I did a basic example compiling this code, I named the source test.cpp:

// test.cpp
#include <iostream>

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

Then I ran this in the terminal:

clang test.cpp

I got this output when compiling:

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)

But it worked fine printing "Hello World" and everything goes fine until here, but when I want to run clang-tidy I get the following output when I run this, I took the reference from here 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.

I read this thread but this seems to apply for clang compilation and I don't know if this also applies for clang extra tools, clang-tidy in particular: How to compile Clang on Windows

like image 766
Wambitz Avatar asked Oct 08 '18 21:10

Wambitz


People also ask

How do I run a clang file in Windows?

You can install clang-format and git-clang-format via npm install -g clang-format . To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows.

How do I run clang tidy on folder?

Run clang-tidy on you entire codebase In the build folder, run run-clang-tidy . It might be a different command ( run-clang-tidy.py or run-clang-tidy-VERSIONNUMBER ) depending on your distro's packaging preference.


1 Answers

Just put -- (minus minus) on the command line at the end

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

You would normally put your cl,gcc,clang arguments afterwards

clang-tidy -checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus* test.cpp -- -DDEBUG -I./include
like image 179
MyDeveloperDay Avatar answered Oct 22 '22 23:10

MyDeveloperDay