问题描述
我正在使用Clang C API进行解析和诊断.我注意到我一直在使用相同的标头包,因此我决定尝试使用PCH或PTH来提高性能.
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.
但是我得到的诊断是clang_parseTranslationUnit
时未使用PCH和PTH:
But i'm getting diagnostics that neither PCH nor PTH were used while clang_parseTranslationUnit
:
- 在编译期间未使用的参数:'-emit-pth'
- /tmp/system/include/libcxx/iostream.pth:链接器"输入未使用
- 在编译过程中未使用的参数:'-emit-pch'
- /tmp/system/include/libcxx/iostream.pch:链接器"输入未使用
我很惊讶在解析时未使用PCH和PTH,那么如何使用PCH或PTH或任何其他方法来提高解析性能?
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是使用clang++ -x c++-header iostream -emit-pth -o iostream.pth
,PCH以类似方式生成的
PTH was generated using clang++ -x c++-header iostream -emit-pth -o iostream.pth
, PCH in similar way
更新1:
我找到了 PCH使用示例:
// 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?
推荐答案
需要在每个参数前加上-Xclang
:
One needs to include -Xclang
before each argument:
char *args[] = { "-Xclang", "-include-pch", "-Xclang", "IndexTest.pch" };
请参见 https://reviews.llvm.org/diffusion/L/browse/cfe/trunk/test/Index/c-index-pch.c 以获得灵感.
这篇关于如何使用PCH或PTH提高clang解析性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!