$./clang -cc1 -emit-pth test/test.h -o test/test.h.pth
test/test.h:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
查找发现,clang -cc1选项默认在自己的目录搜索:
Builtin includes
Clang tools need their builtin headers and search for them the same way Clang does. Thus, the default location to look for builtin headers is in a path $(dirname /path/to/tool)/../lib/clang/3.3/include relative to the tool binary. This works out-of-the-box for tools running from llvm’s toplevel binary directory after building clang-headers, or if the tool is running from the binary directory of a clang install next to the clang binary.
Tips: if your tool fails to find stddef.h or similar headers, call the tool with -v and look at the search paths it looks through.
所以,我们要手动加上头文件的路径了,
./clang -cc1 -I/usr/include/ -I/usr/lib/gcc/x86_64-linux-gnu/4.8/include -emit-pth test/test.h -o test/test.h.pth
其中 -I/usr/include 是找 stdio.h,而 I/usr/lib/gcc/x86_64-linux-gnu/4.8/include 是找 stddef.h.不过每次这样加路径似乎很麻烦,所以,也可以写进/etc/bash.bashrc:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib