15

ここでclangとclang-tidyを初めて使用します。

このタイプの構造を持つプロジェクトがあります。 project/ - build/ - cmake/ - component1/ - src/ - someFile.cpp - someFile2.cpp - someFile.hpp - someFile2.hpp - component2/ - etc... -

project/component1/このコマンドですべてのファイルを確認するために clang-tidy を使用すると、次のようになります。clang-tidy project/component1/src/* -checks=-*,clang-analyzer-*,-clang-analyzer-alpha*

次のようなエラーがスローされます。 $HOME/project/component1/src/someFile.cpp:18:10: error: 'project/component1/someFile.hpp' file not found [clang-diagnostic-error] \#include "component1/someFile.hpp"

4

3 に答える 3

21

この回答は、CMake を使用してプロジェクトを管理する場合にのみ役立ちます。

CMake には、コマンド ライン オプションを使用したすべてのコンパイラ呼び出しを含む .json ファイルを作成するオプションがあります。このファイルは、次のオプションを使用して 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:
    http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an
    example of setting up Clang Tooling on a source tree.

ドキュメントに記載されているように、CMAKE_EXPORT_COMPILE_COMMANDS変数を設定して CMake で .json ファイルを生成し、CMake 出力ディレクトリを clang-tidy に渡す必要があります。Clang-tidy は、.json ファイル内のコマンドからインクルード パスを取得します。

于 2016-09-20T14:30:24.437 に答える