Vim YouCompleteMe Mac OS C family 系统库函数不能自动补全

来源:互联网 发布:csdn黑马程序员 编辑:程序博客网 时间:2024/06/06 06:47

之前还好好的,升级Xcode 和 command tools 后突然发现 YouCompleteMe 不能对c 语言库函数(printf 等)自动补全了,以及出现对 NULL 等 宏定义提示未定义等情况,折腾了一上午,各种搜索,最终还是在官方文档上找到了答案,在此记录一下, 也希望能帮助其他遇到这个问题的人。

  1. 确认.ycm_extra_conf.py 路径时候配对了:
    • let g:ycm_global_ycm_extra_conf=’/your_path/.ycm_extra_conf.py’
  2. 确认 .ycm_extra_conf.py路径配置没有问题,那么再检查一下.ycm_extra_conf.py文件内容时候有问题(因为有时候不小心按了一下键盘导致内容发生改变,我就翻过一次这样错误,在flags 列表里面添加path 的时候少些了一个逗号,导致自动补全失败,最好的方式就是和官方最新的文件用对比工具比较一下,看看时候有改动)
  3. 如果以上问题都确认,并排除,那试试官方给出的方法,也就是今遇到问题的解决方法:
    Completion doesn’t work with the C++ standard library headers

    This is caused by an issue with libclang that only affects some operating systems. Compiling with clang the binary will use the correct default header search paths but compiling with libclang.so (which YCM uses) does not.

    Mac OS X is normally affected, but there’s a workaround in YCM for that specific OS. If you’re not running that OS but still have the same problem, continue reading.

    The workaround is to call echo | clang -v -E -x c++ - and look at the paths under the #include <…> search starts here: heading. You should take those paths, prepend -isystem to each individual path and append them all to the list of flags you return from your FlagsForFile function in your .ycm_extra_conf.py file.

    在terminal 里面输入: echo | clang -v -E -x c++ - :
    这里写图片描述

    把红框里面的的路径全部添加的.ycm_extra_conf.py 的 flag 列表里面:
    这里写图片描述

    注意:最后一行是以逗号 , 结尾的.

  4. 最后:不管遇到什么问题查阅官方文档可能是快的解决问题方式

原创粉丝点击