使用Clang(clang_complete,YouCompleteMe)进行Vim(C/C++完成)的C系列语义自动完成插件

sta*_*ant 17 vim autocomplete clang libclang clang-complete

我在Windows上使用64位Vim,这个版本Haroogan:

+python27
+python33
+huge
Run Code Online (Sandbox Code Playgroud)

我试图用clang_complete,所以我把libclang.dll图书馆在这里,我建立了我的vimrc正确.libclang.dll找到了.

但是当我打开*.cpp文件时,我现在有一条消息:

libclang 找不到内置包含这将导致缓慢完成代码

但我根本没有完成......

我发现这篇文章的内容是我使用的构建Vim版本的人,但没有明确指示该怎么做.有人可以帮忙吗?

UPDATE

这是我做的:

  1. 为Windows带来Vim YouCompleteMe
  2. 接过LLVM用于Windows
  3. 从中获取liclang.dll并将其粘贴在YCM python目录中
  4. 拿了.ycm_extra_conf.py并用我的cpp文件卡住它

它几乎工作(我没有任何错误消息),但我仍然得到: 没有汽车

Ale*_*aev 25

clang_complete


感谢您使用Vim for Windows,希望您喜欢.

要解决您的问题,您必须使用.clang_complete文件.阅读更多相关信息:h clang_complete.简而言之,您可以将此文件放入任何项目的根目录中(即,对于每个项目,此文件可能不同,完全有意义,因为不同的项目具有不同的工具链配置).以下是MinGW-w64工具链的示例:

-ID:/Toolchains/x64/MinGW-w64/4.8.1/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++
-ID:/Toolchains/x64/MinGW-w64/4.8.1/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++/x86_64-w64-mingw32
-ID:/Toolchains/x64/MinGW-w64/4.8.1/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++/backward
-ID:/Toolchains/x64/MinGW-w64/4.8.1/lib/gcc/x86_64-w64-mingw32/4.8.1/include
-ID:/Toolchains/x64/MinGW-w64/4.8.1/lib/gcc/x86_64-w64-mingw32/4.8.1/include-fixed
-ID:/Toolchains/x64/MinGW-w64/4.8.1/x86_64-w64-mingw32/include

-ID:/Libraries/x64/MinGW-w64/4.8.1/Boost/1.54.0/include

-ID:/Libraries/x64/MinGW-w64/4.8.1/Qt/4.8.5/include

-ID:/Libraries/x64/MinGW-w64/4.8.1/Eigen/3.1.3/include

"-ID:/Libraries/x64/MinGW-w64/4.8.1/Example with Spaces/0.0.1/include"

-std=c++11

-DUNICODE
Run Code Online (Sandbox Code Playgroud)

当您使用Vim编辑项目中的某个文件时,clang_complete向后遍历已编辑文件的所有父目录,直到它在第一个.clang_complete要读取的文件中发生故障.然后它读取所有这些标志/开关/定义,并在调用libclang完成期间使用它们.

YouCompleteMe


这几天,我不再使用clang_complete了.Vim还有更强大的语义自动完成插件.这是YouCompleteMe.我强烈建议你试一试.对于C语言语言的语义完成(C/C++/Objective-C/Objective-C++),它也使用libclang.它依赖于强大的C++后端,因此非常快.它与syntastic有很好的集成(另一个必须有Vim的插件).它具有跳转到定义的能力,等等​​.

Since it's written in C++ and glued to Vim via Python, you'd have to compile the C++ back end. To ease the pain you can download prebuilt and ready to use YCM plugin from my Vim YouCompleteMe for Windows. I've built it for both x86 and x64 architectures. The native component is called ycm_core.pyd. As usual the architecture of the Vim build you chose has to match the YCM build (i.e. ycm_core.pyd). YCM can work ONLY with Python 2 (not 3), so just make sure that you have Python 2 DLL (e.g. python27.dll) and Python 2 Interpreter (python.exe) in the PATH environment variable.

如果你需要LLVM/Clang,你也可以从我这里下载:LLVM for Windows.同样,只要确保你libclang.dllPATH环境变量(推荐)旁边ycm_core.pyd.再次支持x86和x64架构,并且架构应该再次与Vim和YCM相匹配.

关于完成:

他应该神奇地找到STL的位置吗?

Of course not! This is just an autocompletion system based on Clang front end. How is it supposed to know which toolchain you're currently using to compile your code? You could use anything: Visual C++, Borland C++, GCC, MinGW, MinGW-w64, LLVM/Clang, etc. Each of them has their own standard library and runtime supplied. Thus, in each case you'd have to specify all the paths which your current toolchain uses to find standard includes.

For example, in case of GCC, MinGW, MinGW-w64, you can run the following in POSIX shell:

g++ -E -x c++ - -v < /dev/null
Run Code Online (Sandbox Code Playgroud)

Or in Windows Command Prompt:

g++ -E -x c++ - -v < nul
Run Code Online (Sandbox Code Playgroud)

And look for the following excerpt:

#include <...> search starts here:
 d:\toolchains\x64\mingw-w64\4.8.1\posix\seh\bin\../lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++
 d:\toolchains\x64\mingw-w64\4.8.1\posix\seh\bin\../lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++/x86_64-w64-mingw32
 d:\toolchains\x64\mingw-w64\4.8.1\posix\seh\bin\../lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++/backward
 d:\toolchains\x64\mingw-w64\4.8.1\posix\seh\bin\../lib/gcc/x86_64-w64-mingw32/4.8.1/include
 d:\toolchains\x64\mingw-w64\4.8.1\posix\seh\bin\../lib/gcc/x86_64-w64-mingw32/4.8.1/include-fixed
 d:\toolchains\x64\mingw-w64\4.8.1\posix\seh\bin\../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/include
End of search list.
Run Code Online (Sandbox Code Playgroud)

This tells you all the paths to standard includes which GCC, MinGW, MinGW-w64 use implicitly during compilation of your code.

For LLVM/Clang, you can do the same:

clang++ -E -x c++ - -v < /dev/null
Run Code Online (Sandbox Code Playgroud)

Or:

clang++ -E -x c++ - -v < nul
Run Code Online (Sandbox Code Playgroud)

当您知道路径时,您可以愉快地将它们添加到路径中.ycm_extra_conf.py.例如,在我的情况下:

'-I',
'D:/Toolchains/x64/MinGW-w64/4.8.1/POSIX/SEH/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++',
'-I',
'D:/Toolchains/x64/MinGW-w64/4.8.1/POSIX/SEH/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++/x86_64-w64-mingw32',
'-I',
'D:/Toolchains/x64/MinGW-w64/4.8.1/POSIX/SEH/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++/backward',
'-I',
'D:/Toolchains/x64/MinGW-w64/4.8.1/POSIX/SEH/lib/gcc/x86_64-w64-mingw32/4.8.1/include',
'-I',
'D:/Toolchains/x64/MinGW-w64/4.8.1/POSIX/SEH/lib/gcc/x86_64-w64-mingw32/4.8.1/include-fixed',
'-I',
'D:/Toolchains/x64/MinGW-w64/4.8.1/POSIX/SEH/x86_64-w64-mingw32/include',
Run Code Online (Sandbox Code Playgroud)