我的YouCompleteMe Vim插件不支持STL。

10
我刚按照Github上的介绍编译并安装了Vim、Vundle和YouCompleteMe插件。但是在我的Vim中,YouCompleteMe插件不能很好地工作。它可以自动补全变量名,但无法自动补全STL对象(vector、map)的操作。甚至不能自动补全类中的"this->"。它总是告诉我"(^U^N^P) Pattern not found."。你们见过这种情况吗?我使用的是Ubuntu 12.04。我该怎么办?

3
你能确认你已经安装了所有的依赖项吗?你具体遵循了哪些步骤?你是按照“超快速”还是“完整”教程进行的操作?为什么你要在这个通用性很强的网站上提问,而不是在 YCM 的问题跟踪器上提问? - romainl
我也遇到了一些问题,无法让YCM正常工作。我进行了快速安装,但现在尝试深入了解为什么它不起作用,却有点迷失在如何排除YCM故障的过程中。有很多部分我不理解。@romaini,你能给出一些排除故障的建议吗? - Tegra Detra
@romainl 我走了一条漫长的编译之路,仍然遇到了麻烦,然后查看了ycm配置文件,意识到那就是我遇到的问题。我不知道我的标准库在哪里 =。 - Tegra Detra
2个回答

6

插件的GitHub存储库上的自述文件现在解决了该问题。

这是由libclang引起的问题。从clang编译二进制文件使用了正确的默认头文件搜索路径,但从libclang.so编译时没有使用。该问题似乎对某些操作系统影响更大。特别是OS X Mavericks似乎有问题。

当前的解决方法是调用echo | clang -v -E -x c++ -,并查看在# include <...>搜索开始于:标题下的路径。您应该采取这些路径,并为每个单独路径添加-isystem前缀,然后将它们全部附加到您在.ycm_extra_conf.py文件中返回的标志列表中的FlagsForFile函数中。

您还可以查看相应的问题


3

我也在这里寻找答案,我不懂Python,以前也没有黑过其他的东西。那么这就是我解决问题的方法。

  1. Find the error message. I went to ~/.vim/bundle/YouCompleteMe and grepped for "builtin includes" . Why? because that is part of the error message

    • a. I did not find it there so went to a higher level (cd ..) and repeat.
    • b. Found it see below ./vundle/plugin/libclang.py: print "WARNING: NxD libclang can not find the builtin includes."
  2. Modified Error message to ensure that this file was being run (my initials NxD) - worked.

  3. The message is printed by initClangComplete
  4. The message is printed after this invocation builtinHeaderPath = getBuiltinHeaderPath(library_path) hence we delve deeper into builtinHeaderPath
  5. getBuiltinHeaderPath runs a loop on known directories. I have 2 clang installations

    • a. ~/Downloads directory - where all software in the world is dumped
    • b. /usr/local because I wanted the latest clang which I cloned, compiled and built

    I added both the paths to this array : knownPaths

      "/usr/local/include",
      "/usr/local/lib/clang/3.3",
      "/home/nxd/Downloads/clang+llvm-3.2-x86_64-linux-ubuntu-12.04/clang/3.2"
    

    I noted that "," is the separator of array elements in python. I also earlier noted that print -> puts a message out in python and arguments are c-style %s, %d etc work - (that's how the "builtin include" message came on the screen in the first place)

  6. I also dumped some print statements into the loop so see what it was seeing and what it was doing.

    part code modified function "getBuiltinHeaderPath"

      print "active path from knownPaths is |%s|" %path
      files = os.listdir(path)
      print " files in path is |%s|" % files
      print " len (files) is |%d|" % len(files)
      if len(files) >= 1:
        files = sorted(files)
        subDir = files[-1]
      else:
        subDir = '.'
      # nxd -
      subDir = '.'
      path = path + "/" + subDir + "/include/"
      print " len (files) is |%d|" % len(files)
      print " files[-1] is |%s|" % files[-1]
      print "searching in path : |%s| " % path
    
  7. I realised that the expected behaviour of files[-1] was not what the author intended and modified it after the if condition to stay unchanged.

  8. Restart vim with a new cpp file and looked at :messages - It worked.

    Hope that helps.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接