在clang 的文档中,您可以找到源代码示例:
// excludeDeclsFromPCH = 1, displayDiagnostics=1
Idx = clang_createIndex(1, 1);
// IndexTest.pch was produced with the following command:
// "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
// This will load all the symbols from 'IndexTest.pch'
clang_visitChildren(clang_getTranslationUnitCursor(TU), TranslationUnitVisitor, 0);
clang_disposeTranslationUnit(TU);
// 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);
clang_visitChildren(clang_getTranslationUnitCursor(TU), TranslationUnitVisitor, 0);
clang_disposeTranslationUnit(TU);
虽然我没有检查它。您找到有效的解决方案了吗?也看看我关于 PCH 的问题。