<div dir="ltr">For some reason clang_findIncludesInFile did not find inclusion in file (1 inclusion actually). I've checked test file with clang and no diagnostics are provided (seems to be correct).<div><br><div>Sources:</div>
<div>---</div><div><div>#include <iostream></div><div>#include <clang-c/Index.h></div><div><br></div><div>static CXVisitorResult include_visit(void *context, CXCursor cursor, CXSourceRange range) {</div><div><br>
</div><div>  CXFile file = clang_getIncludedFile(cursor);</div><div>  CXString filename = clang_getFileName(file);</div><div><br></div><div>  fprintf(stderr, "    include [%s]\n", clang_getCString(filename));</div>
<div><br></div><div>  clang_disposeString(filename);</div><div><br></div><div>  // continue</div><div>  return CXVisit_Continue;</div><div>}</div><div><br></div><div>CXCursorAndRangeVisitor visitor = {</div><div>  .context = 0,</div>
<div>  .visit = include_visit</div><div>};</div><div><br></div><div>char * cx_results[] = {</div><div>  "CXResult_Success",</div><div>  /**</div><div>   * \brief One of the parameters was invalid for the function.</div>
<div>   */</div><div>  "CXResult_Invalid",</div><div>  /**</div><div>   * \brief The function was terminated by a callback (e.g. it returned</div><div>   * CXVisit_Break)</div><div>   */</div><div>  "CXResult_VisitBreak"</div>
<div>};</div><div><br></div><div>void showInclusions(CXTranslationUnit TU, char *src_filename, unsigned filesize) {</div><div>    </div><div>    CXFile file = clang_getFile(TU, src_filename);</div><div>    fprintf(stderr, "filename=[%s] size=[%u]\n", src_filename, filesize);</div>
<div><br></div><div>    CXResult result = clang_findIncludesInFile(TU, file, visitor);</div><div>    fprintf(stderr, "result = %s\n", cx_results[result]);</div><div>}</div><div><br></div><div>unsigned getfilesize(char* filename)</div>
<div>{</div><div><span class="" style="white-space:pre">    </span>FILE *fp = fopen(filename, "r");</div><div><span class="" style="white-space:pre"> </span>fseek(fp, 0L, SEEK_END);</div><div><span class="" style="white-space:pre">   </span>unsigned sz = ftell(fp);</div>
<div><span class="" style="white-space:pre">    </span>fclose(fp);</div><div><span class="" style="white-space:pre">        </span>return sz;</div><div>}</div><div><br></div><div>const char * const params[] = {</div><div>    "-c",</div>
<div>    "-x",</div><div>    "c++"</div><div>};</div><div><br></div><div>int main(int argc, char** argv)</div><div>{</div><div>    std::cout << "Starting ----" << std::endl;</div>
<div><br></div><div>    CXIndex index = clang_createIndex(false, false);</div><div>    </div><div>    // command-line tu</div><div>    fprintf(stderr, "command-line file =============\n");</div><div>    char *filename = argv[1];</div>
<div>    unsigned filesize = getfilesize(filename);</div><div>    CXTranslationUnit commandLineTu = clang_parseTranslationUnit(index, filename, params, 3, 0, 0, CXTranslationUnit_None);</div><div>    </div><div>    if (!commandLineTu) {</div>
<div>      fprintf(stderr, "failed to parse TU\n");</div><div>      return 1;</div><div>    }</div><div>    </div><div>    showInclusions(commandLineTu, filename, filesize);</div><div>    </div><div>    clang_disposeTranslationUnit(commandLineTu);</div>
<div>    clang_disposeIndex(index);</div><div><br></div><div>    return 0;</div><div>}</div></div><div>---</div><div><br></div><div>Test files:</div><div>1. "clang_include.cpp":</div><div><div>---</div><div>#include "a.h"</div>
<div><br></div><div>int a = 10;</div></div><div>---</div><div>2. "a.h" exists and is empty.</div><div><br></div><div><br></div><div>Build is done in "build folder", sources are in "jni" folder, test files are in "test" folder</div>
<div>Execution:</div><div><br></div><div><div>mba-anton:build asmirnov$ ./clang_include ../test/test_include.cpp </div><div>Starting ----</div><div>command-line file =============</div><div>filename=[../test/test_include.cpp] size=[27]</div>
<div>result = CXResult_Success</div></div><div><br></div></div><div>Any thoughts?</div></div>