我为VIM安装了YCM和Synthetic,通常它们工作正常,但是当我的代码检测到一些错误时,我有问题,这表明找不到一些头文件(这是我的项目头文件).
我的目录树显示如下:
TOP ├── debug │ ├── debug.c │ ├── debug.h │ ├── debug.mk │ └── instrument.c ├── driver │ ├── driver.c │ ├── driver_ddi.c │ ├── driver_ddi.h │ ├── driver.h │ └── driver.mk ├── include │ └── common.h ├── libs ├── Makefile ├── mw │ ├── manager.c │ └── mw.mk └── root ├── main.c └── root.mk
我将.ycm_extra_conf.py复制到TOP,同时我也会在TOP生成标签和cscope文件,因此每次在TOP上打开文件,如:
howchen@host:~/Work/c/sample/src -> gvim ./driver/driver.c
以确保每次可以在VIM中添加标签和cscope文件.问题是,如果我打开driver.c,其中包含头文件:driver.h,driver_ddi.h,debug.h,common.h,代码如下:
#include <stdio.h> #include <stdlib.h> #include "math.h" #include "common.h" #include "debug.h" #include "driver_ddi.h" #include "driver.h"
合成或YCM总是显示它找不到common.h和debug.h,其他头文件都可以.
我的YCM和合成配置部分在vimrc文件中:
" YCM " let g:ycm_extra_conf_globlist = ['~/.vim/bundle/YouCompleteMe/cpp/ycm/*','!~/*'] let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py' " Syntastic let g:syntastic_c_checkers=['make'] let g:syntastic_always_populate_loc_list = 1 let g:syntastic_check_on_open=1 let g:syntastic_enable_signs=1 let g:syntastic_error_symbol = '✗' let g:syntastic_warning_symbol = '⚠' set statusline+=%#warningmsg# set statusline+=%{SyntasticStatuslineFlag()} set statusline+=%*gbar
我的.ycm_extra_conf.py将flags变量写为:
flags = [ '-Wall','-Wextra','-Werror','-Wc++98-compat','-Wno-long-long','-Wno-variadic-macros','-fexceptions','-DNDEBUG','-std=c99',# ...and the same thing goes for the magic -x option which specifies the # language that the files to be compiled are written in. This is mostly # relevant for c++ headers. # For a C project,you would set this to 'c' instead of 'c++'. '-x',#I don't know if I need remove -x 'c','-isystem','../llvm/include','../llvm/tools/clang/include','-I','.','../driver' '-I','../debug' '-I','../include' '-I','../include' ]
我设置的任何错误的标志?
解决方法
从这个问题移到这里.
我发现问题:
flags = [ '-Wall','-I./driver','-I./debug','-I./include',]
我错过了一个逗号,路径应该是./xxx,还有neeeeed’-I /usr/include’和’-I /usr/local / include’.