基本的に、ubuntu 12.04 の clang 3.4 (trunk 192426) に関するこれらの 2 つのチュートリアル1 2に従って、C ファミリのソース コード プロジェクトを解析するツールを作成しています。
公式のチュートリアルに基づいて、私は通り過ぎることができると言っていますがcompile_commands.json
、-p
入力しただけでは、$ ./main -p [path of compile_commands.json]
位置引数が欠落していると不平を言います。すべてのファイル名を引数として渡す必要があるようですが、プロジェクトが本当に巨大な場合は実用的ではありません。指定されたすべてのファイルを確認せずに単純に解析できると思いますcompile_commands.json
が、それを有効にする方法がわかりません。
CommonOptionsParserをカスタマイズするためのチュートリアルが見つからないため、代わりにCompilationDatabaseクラスを使用します。に戻るダミーの訪問者がいるtrue
のでVisitStmt
、スキップしますVisitDecl
。関数は非常に単純ですVisitType
。main
int main(int argc, const char **argv) {
string errorMsg = "";
CompilationDatabase *cd = CompilationDatabase::autoDetectFromDirectory (argv[1], errorMsg);
ClangTool Tool(*cd, cd->getAllFiles());
int result = Tool.run(newFrontendActionFactory<ExampleFrontendAction>());
return result;
}
opencv
cmakeを使用することで、compile_commands.json
(正しい?)の正確性が保証されるため、解析することを選択しました。ただし、多くのエラーが表示されます(最後に添付)。stdarg.h
LibTooling は、stddef.h
も も見つからないと文句を言いますemmintrin.h
。それはclangのFAQですが、なぜそれが起こるのかは述べていますが、libtoolingを使用しているときにそれを解決する方法は述べていません。for clangのすべての引数をclang -###
渡して解決できますが、libtooling の使用中にこれらの引数を渡す方法は?
# include <stdarg.h>
^
1 error generated.
Error while processing /home/jcwu/repos/opencv/3rdparty/openexr/IlmImf/ImfCompressionAttribute.cpp.
In file included from /home/jcwu/repos/opencv/3rdparty/libjpeg/jmemansi.c:16:
/home/jcwu/repos/opencv/3rdparty/libjpeg/jinclude.h:35:10: fatal error: 'stddef.h' file not found
#include <stddef.h>
^
1 error generated.
Error while processing /home/jcwu/repos/opencv/3rdparty/libjpeg/jmemansi.c.
error: no suitable precompiled header file found in directory '/home/jcwu/repos/opencv/modules/legacy/precomp.hpp.gch'
1 error generated.
Error while processing /home/jcwu/repos/opencv/modules/legacy/src/hmmobs.cpp.
In file included from /home/jcwu/repos/opencv/3rdparty/libwebp/enc/quant.c:17:
In file included from /home/jcwu/repos/opencv/3rdparty/libwebp/enc/../dsp/../enc/vp8enci.h:17:
/usr/include/string.h:34:10: fatal error: 'stddef.h' file not found
#include <stddef.h>
^
1 error generated.
Error while processing /home/jcwu/repos/opencv/3rdparty/libwebp/enc/quant.c.
In file included from /home/jcwu/repos/opencv/modules/imgproc/opencv_test_imgproc_pch_dephelp.cxx:1:
In file included from /home/jcwu/repos/opencv/modules/imgproc/test/test_precomp.hpp:12:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/iostream:40:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/ostream:40:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/ios:39:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/iosfwd:42:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/bits/postypes.h:42:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/cwchar:46:
/usr/include/wchar.h:40:11: fatal error: 'stdarg.h' file not found
# include <stdarg.h>
====更新====
CommonOptionsParser.cpp のソース コードを読んでください。これは、FixedCompilationDatabase を使用して、 -- の後の引数で CompilationDatabase を推測し、 -- の前に引数を渡します。カスタム (CommonOptionParser では -p のみ) オプションです。私の場合、compile_commands.json が必要なので、CommonOptionsParser の使用をスキップできます。
したがって、私の問題は、compile_commands.json があるときに「clang -###」から LibTooling にこれらのオプションを渡す方法に縮小されますか? 解析したいファイルごとにシェルコマンドを呼び出す必要がありますか?
====更新====
compile_commands.json を変更する方が簡単だと思います。その CMakeList.txt によって生成された Makefile は正しくコンパイルできるため、CMake によって生成された compile_commands.json にシステム ヘッダー ファイル フォルダーが正しく含まれない理由がわかりません。