clang -cc1 error : file not found

Hi, everyone!
I have a simple source file test.c,as follow:


int main() {
printf(“Hello World\n”);
return 0;

When I use command:$ clang test.c -o test .It’s OK, and generate the test executable.
But, when use command:$ clang test.c -cc1 test.c -o test or command:$clang -cc1 test.c -ast-print .Error occur.
:test.c:1:9: fatal error: ‘stdio.h’ file not found

The office docments say that:“Users should not run clang -cc1 directly, because -cc1 options are not guaranteed to be stable” from:
Now I want to print the ast…
The platform is ubuntu14.04, LLVM version is 3.6, the same to 3.5.
I want to print the ast. Is there anyone can help me? Thinks very much^.^


The -cc1 flag is useful in some cases, but if you just want to print the ast, you can use the -Xclang switch as well. -cc1 will remove all builtin settings from clang, which includes standard defines, and standard include paths. -Xclang gives you access to the full set of clang flags for the next argument, it’s like passing it to “clang -cc1” directly, but doesn’t require all of the include paths etc to be set.

$ clang -fsyntax-only -Xclang -ast-dump ./test.c


$ clang -Xclang -ast-dump -o test ./test.c

when using -cc1, you must specify all include paths, and any other “normal” settings that clang would use for c/c++ compilation. If you do

$ clang -v -o test ./test.c

you should be able to see the full clang command with the -cc1 argument.

But, since you’re interested in dumping the ast, “-Xclang -ast-dump” is all you need.


Whoops, forgot to attach it to that email, but here [1] is a good reference page about builtins.