问题
I'm using Clang C API for parsing and getting diagnostics. I've noticed that i'm using the same bundle of headers all the time, so i've decided to try to use PCH or PTH to increase performance.
But i'm getting diagnostics that neither PCH nor PTH were used while clang_parseTranslationUnit
:
- argument unused during compilation: '-emit-pth'
- /tmp/system/include/libcxx/iostream.pth: 'linker' input unused
- argument unused during compilation: '-emit-pch'
- /tmp/system/include/libcxx/iostream.pch: 'linker' input unused
I'm surprised that PCH and PTH were not used while parsing, so how can i use PCH or PTH or any other approach to increase parsing performance?
PS.
PTH was generated using clang++ -x c++-header iostream -emit-pth -o iostream.pth
, PCH in similar way
Update 1:
I've found PCH usage example:
// This will load all the symbols from 'IndexTest.c', excluding symbols
// from 'IndexTest.pch'.
char *args[] = { "-Xclang", "-include-pch=IndexTest.pch" };
TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args, 0, 0);
The problem is that now i'm getting another diagnostics warning:
'-pch=/system/include/libcxx/iostream.pch' file not found
Looks like command-line arguments were parsed incorrectly.. What am i doing wrong?
回答1:
One needs to include -Xclang
before each argument:
char *args[] = { "-Xclang", "-include-pch", "-Xclang", "IndexTest.pch" };
See https://reviews.llvm.org/diffusion/L/browse/cfe/trunk/test/Index/c-index-pch.c for inspiration.
来源:https://stackoverflow.com/questions/26830997/how-to-increase-clang-parsing-performance-using-pch-or-pth