Company clang 的用法,如何才能补全自己安装的库?

company-clang 不用配置就能补全 stdio.h,但是自己安装却不行,比如我安装了 cairo,不能开箱即用,好像需要设置 include path,下面的命令可以获得补全:

$ cat hello.c | clang -fsyntax-only -Xclang -code-completion-macros -x c \
    -Xclang -code-completion-at=-:19:9  -I/usr/local/include/cairo -

-I/usr/local/include/cairo 这个选项要怎么给 company-clang 设置?我目前只要考虑 per buffer 层次的,不用 buffer 会用不同的库。

还有 M-x company-clang-set-prefix 命令是干嘛的?对于 clang 的 -include 选项,看不懂什么意思

Adds an implicit #include into the predefines buffer which is read before the source file is preprocessed.

(setq company-clang-arguments '("-I/usr/local/include/cairo"))

关于-include可以看info gcc的输出:

-include FILE'
     Process FILE as if '#include "file"' appeared as the first line of
     the primary source file.  However, the first directory searched for
     FILE is the preprocessor's working directory _instead of_ the
     directory containing the main source file.  If not found there, it
     is searched for in the remainder of the '#include "..."' search
     chain as normal.

     If multiple '-include' options are given, the files are included in
     the order they appear on the command line.

简而言之,就是像手工#include "file"的效果一样。

正解。进一步的问题是文件 A 用 Cairo、文件 B 用 GSL、文件 C 用 PLplot,每个 buffer 都需要不同的参数?另外,不知道给 Clang 传入多余的 -I 会不会使 Clang 变慢?具体怎么设置还是个难题,File Local Variable 可能是一个方案。

刚发现 #include <cairo.h> 改成 #include <cairo/cairo.h> 就不需要配置了,Clang 会自动找到后面这个文件。