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

时间:2018-10-08 21:12:28

标签: c++ clang 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

1 个答案:

答案 0 :(得分:0)

只需在命令行末尾添加-(减号)

  private Button dynakey[]= new Button[9];//8 buttons       
        //Parse the values of buttons 
        try {
            String sButtonString="";
            JSONArray jArrayButton = 
            ResponseUIObject.getJSONArray("BUTTON");
            for(int k=0;k<8;k++) {
                int ID=k+1;
                String dynakeyID = "dynakey"+(ID);
                int resID  = getResources().getIdentifier(dynakeyID, "id", getPackageName());
                dynakey[ID] =(Button) findViewById(resID);
                sButtonString= jArrayButton.getString(k-0);
                 //Set Enable or Disable logic here
                if ((ID% 2) == 0) {
                    // number is even its a right side button //Change style of button depending upon the value
                    if(sButtonString.trim().length() == 0) {
                        //If string is not null or not empty then Enable the button else not
                        dynakey[ID].setTextAppearance(this, R.style.RightDisableDynakeyButton);
                    }else{
                        dynakey[ID].setTextAppearance(this, R.style.RightEnableDynakeyButton);
                    }
                }
                else {
                    // number is odd its a left side button //Change style of button depending upon the value
                    if(sButtonString.trim().length() ==0) {
                        //If string is not null or empty then Enable the button else not
                        dynakey[ID].setTextAppearance(this, R.style.LeftDisableDynakeyButton);
                    }else{
                        dynakey[ID].setTextAppearance(this, R.style.LeftEnableDynakeyButton);
                    }
                }
            }
        } 

您通常会在后面加上cl,gcc,clang参数

parse_url