clang无法补全c++函数,但是c函数可以

pans-MacBook-Pro:oj pan$ clang --version clang version 6.0.1 (tags/RELEASE_601/final) Target: x86_64-apple-darwin17.4.0 Thread model: posix InstalledDir: /usr/local/opt/llvm/bin

ProductName: Mac OS X ProductVersion: 10.13.3 BuildVersion: 17D47

GNU Emacs 25.3.1

c++函数就不行

c函数补全是ok的

大家帮忙看下怎么才能搞定。。新手。。

clang-err报错信息:

/usr/local/opt/llvm/bin/clang -fsyntax-only -Xclang -code-completion-macros -x c++ -I/usr/include/sys/ -Xclang -code-completion-at=-:26:17 -

In file included from :1: In file included from /usr/local/Cellar/llvm/6.0.1/include/c++/v1/iostream:38: In file included from /usr/local/Cellar/llvm/6.0.1/include/c++/v1/ios:215: In file included from /usr/local/Cellar/llvm/6.0.1/include/c++/v1/iosfwd:90: In file included from /usr/local/Cellar/llvm/6.0.1/include/c++/v1/wchar.h:119: In file included from /usr/include/wchar.h:92: In file included from /usr/include/_wctype.h:42: In file included from /usr/include/__wctype.h:62: /usr/include/_types/_wctype_t.h:32:9: error: unknown type name ‘__darwin_wctype_t’ typedef __darwin_wctype_t wctype_t; ^ In file included from :1: In file included from /usr/local/Cellar/llvm/6.0.1/include/c++/v1/iostream:38: In file included from /usr/local/Cellar/llvm/6.0.1/include/c++/v1/ios:215: In file included from /usr/local/Cellar/llvm/6.0.1/include/c++/v1/iosfwd:90: In file included from /usr/local/Cellar/llvm/6.0.1/include/c++/v1/wchar.h:119: /usr/include/wchar.h:98:15: error: unknown type name ‘FILE’ wint_t fgetwc(FILE *); ^ /usr/include/wchar.h:99:44: error: unknown type name ‘FILE’ wchar_t *fgetws(wchar_t * __restrict, int, FILE * __restrict); ^ /usr/include/wchar.h💯24: error: unknown type name ‘FILE’ wint_t fputwc(wchar_t, FILE *); ^ /usr/include/wchar.h:101:40: error: unknown type name ‘FILE’ int fputws(const wchar_t * __restrict, FILE * __restrict); ^ /usr/include/wchar.h:102:11: error: unknown type name ‘FILE’ int fwide(FILE *, int); ^ /usr/include/wchar.h:103:14: error: unknown type name ‘FILE’ int fwprintf(FILE * __restrict, const wchar_t * __restrict, …); ^ /usr/include/wchar.h:104:13: error: unknown type name ‘FILE’ int fwscanf(FILE * __restrict, const wchar_t * __restrict, …); ^ /usr/include/wchar.h:105:14: error: unknown type name ‘FILE’ wint_t getwc(FILE *); ^ /usr/include/wchar.h:113:23: error: unknown type name ‘FILE’ wint_t putwc(wchar_t, FILE *); ^ /usr/include/wchar.h:117:24: error: unknown type name ‘FILE’ wint_t ungetwc(wint_t, FILE *);

我已经尝试在.clang_complete文件中增加头文件了,但还是一样无法补全

-I/usr/include

-I/usr/include/c++/4.2.1

-I/usr/local/Cellar/llvm/6.0.1/include/c++/v1/

你把代码实际编译一下,看怎样才能用clang编译通过,然后用clang生成json

找到原因及解决方法了,该问题只有在macos上才会碰到; 执行下面几个命令即可,原因可以看注释的网站

install llvm for clang.

brew install llvm echo ‘export PATH=“/usr/local/opt/llvm/bin:$PATH”’ >> ~/.bash_profile sudo xcode-select --switch /Library/Developer/CommandLineTools/ #xcode - macOS 'wchar.h' File Not Found - Stack Overflow

#解决 c++某些函数clang无法找到头文件错误 open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg #This will bring up the prompt to install Xcode tools. sudo xcode-select -s /Library/Developer/CommandLineTools #c++ - 'wchar.h' file not found - Stack Overflow

问下老铁,用 lsp + clang 做补全,要先编译产生 compile_commands.json 文件了,之后才能在全工程内补全么

这个文件主要用于让 C/C++ 的 language server 得到正确的命令行参数。没有是可以的,但是不一定对啊。