'Header file not found' error during clang source to source transformation

Hi guys,

I am doing some basic source to source transformation by iterating through the AST using Clang front-end. And, it is working fine i.e. I am able to get transformed code with insertions.

However, when I have some header file inclusions in the input source code such as “#include<stdio.h”, it produces an error message when transforming the code. It is -

input.c:1:9: fatal error: ‘stdio.h’ file not found

So my question is - how can I avoid getting this error about header files? For all practical use, my input source files will have the header files. Please let me know.

Thanks and regards,

I think you need a compilation database for that http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html. Header search is done by the driver when you compile code, but there’s no driver if you invoke the front-end directly (or if you’re using tooling).

This is a well-known issue that is unfortunately documented extremely poorly (or, rather, the documentation does absolutely nothing to call out what is arguably the single most common failure beyond “I’m missing -I or -l in my compile commands”). The short version: drop your tool in /usr/local/bin and run it from there. The longer version: in the absence of specific options indicating otherwise, the lookup for files usually found in places under /usr is done using $(dirname argv[0])/…/lib/clang//include and similar paths.

Yea, I argued with chandler for a long time that we should just put the internal headers into the tools (compile them in), but was not able to convince him (yet).