Parsing ObjC source file with precompiled headers in libclang


I'm parsing an ObjC source file with libclang by using Python bindings. Parsing itself works fine but since I'm parsing source files which #import framework headers such as UIKit.h and Foundation.h, the parsing is a pretty heavy operation even for the most simple main source files. I would like to use precompiled prefix headers to make the parsing faster, but apparently I'm doing something wrong. Here is the Python code I use:

I /think/ you should be using instead of Index.parse() to
load PCH files. Try:

  tu =

Hi Gregory, is mapped to the clang_createTranslationUnit function in libclang, which is documented to "Create a translation unit from an AST file (-emit-ast).". Since the precompiled header isn't AST file, I don't think that function should be used.

I thought a PCH file could be produced by saving a translation unit with the appropriate save flags. The docs for clang_saveTranslationUnit [1] and the corresponding save flags [2] seem to indicate this.

Do I have a wrong understanding here?