title: libtooling can't find stddef.h nor other headers
body: <p>I am writing a tool to parse C family source code projects basically following these two tutorials <a href="http://kevinaboos.blogspot.com/2013/07/clang-tutorial-part-ii-libtooling.html" rel="noreferrer">1</a> <a href="http://clang.llvm.org/docs/LibTooling.html" rel="noreferrer">2</a> on clang 3.4 (trunk 192426) on ubuntu 12.04.</p>
  
  <p>Based on <a href="http://clang.llvm.org/docs/LibTooling.html" rel="noreferrer">offical tutorial</a>, it says I could pass <code>compile_commands.json</code> by <code>-p</code>, however, if I only type <code>$ ./main -p [path of compile_commands.json]</code>, it will complain about missing positional arguments. It seems like I still need to pass all file names as arguments, which is not practical if the project is really huge. I prefer it could simply parse all files specified in <code>compile_commands.json</code> without asking but can't find out how to turn that on.</p>
  
  <p>Since I can't find a tutorial for <a href="http://clang.llvm.org/doxygen/classclang_1_1tooling_1_1CommonOptionsParser.html" rel="noreferrer">CommonOptionsParser</a> to do any customize thing, I use <a href="http://clang.llvm.org/doxygen/classclang_1_1tooling_1_1CompilationDatabase.html" rel="noreferrer">CompilationDatabase</a> class instead. There is a dummy visitor returning <code>true</code> for <code>VisitStmt</code>, <code>VisitDecl</code> and <code>VisitType</code> so I'll skip that. The <code>main</code> function is pretty simple:</p>
  
  <pre><code>int main(int argc, const char **argv) {
      string errorMsg = "";
      CompilationDatabase *cd = CompilationDatabase::autoDetectFromDirectory (argv[1], errorMsg);
      ClangTool Tool(*cd, cd-&gt;getAllFiles());
  
      int result = Tool.run(newFrontendActionFactory&lt;ExampleFrontendAction&gt;());
  
      return result;
  }
  </code></pre>
  
  <p>I choose <a href="https://github.com/Itseez/opencv" rel="noreferrer"><code>opencv</code></a> to parse since using cmake gaurantee the correctness of <code>compile_commands.json</code>(right?). However, a lot of errors show up (attached in the end). LibTooling complain about it can't find <code>stdarg.h</code>, <code>stddef.h</code> nor <code>emmintrin.h</code>. It's a <a href="http://clang.llvm.org/docs/FAQ.html" rel="noreferrer">FAQ</a> for clang, but it says why that will happen, but didn't say how to solve that while using libtooling. Pass all arguments for <code>clang -###</code> for clang could solve that, but how to pass those arguments while using libtooling? </p>
  
  <pre><code># include &lt;stdarg.h&gt;
            ^
  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 &lt;stddef.h&gt;
           ^
  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 &lt;stddef.h&gt;
           ^
  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 &lt;stdarg.h&gt;
  </code></pre>
  
  <p>==== Update ==== </p>
  
  <p>Read CommonOptionsParser.cpp source code. It uses FixedCompilationDatabase to guess CompilationDatabase by arguments after --, then pass arguments before -- for custom (only -p in CommonOptionParser) options. In my case compile_commands.json is required, so I could skip using CommonOptionsParser. </p>
  
  <p>Therefore my problem reduce to how to pass those options from "clang -###" to LibTooling when I have a compile_commands.json? Should I invoke shell command for every file I want to parse?</p>
  
  <p>==== Update ====</p>
  
  <p>I think modify compile_commands.json might be easier. I'm not sure why the compile_commands.json generated by CMake won't include my system header files folder correctly, since the Makefile generate by that CMakeList.txt could compile correctly, how come the compile_commands.json miss a lot of things. </p>