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
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With