C语言 如何为当前项目配置 .ycm_extra_conf.py 包括 PATH

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21014105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:35:47  来源:igfitidea点击:

How to configure .ycm_extra_conf.py for current project include PATH

cvimmakefileclangyoucompleteme

提问by How Chen

I installed YCM and syntastic for VIM, normally they work fine, but I have problem when it detect some errors in my code, it shows that can NOT find some head files(which is my project head file).

我为 VIM 安装了 YCM 和 Syntastic,通常它们工作正常,但是当它在我的代码中检测到一些错误时出现问题,它表明找不到一些头文件(这是我的项目头文件)。

My directory tree shows below:

我的目录树如下所示:

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

I copied a .ycm_extra_conf.pyto the TOP, meanwhile, I will generated tagand cscopefile at TOP as well, therefore each time I open file on TOP, like:

我复制了一个.ycm_extra_conf.py到 TOP,同时,我也会在 TOP生成tagcscope归档,因此每次我在 TOP 上打开文件,例如:

howchen@host:~/Work/c/sample/src
-> gvim ./driver/driver.c

to make sure each time I can add tagand cscopefile in VIM. The problem is, if I open driver.c, which contain head files: driver.h, driver_ddi.h, debug.h, common.h, code like below:

确保每次我都可以在 VIM 中添加tagcscope归档。问题是,如果我打开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"

the syntasticor YCMalways show it can NOT find common.hand debug.h, other head files are OK.

syntasticYCM总是显示无法找到common.hdebug.h其他头文件是否正确。

My YCM and syntastic config part in vimrc file:

我的 YCM 和 vimrc 文件中的 Syntastic 配置部分:

" 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

My .ycm_extra_conf.pywrite flagsvariable as:

我的.ycm_extra_conf.pyflags变量为:

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',
'-isystem',
'../llvm/tools/clang/include',
'-I',
'.',
'-I',
'../driver'
'-I',
'../debug'
'-I',
'../include'
'-I',
'../include'
]

any wrong flags I set?

我设置的任何错误标志?

采纳答案by Bo Persson

Moved here from the question.

从问题移到这里。

I found the problem:

我发现了问题:

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',
'-isystem',
'../llvm/tools/clang/include',
'-I./driver',
'-I./debug',
'-I./include',
]

I missed a comma and path should be ./xxx, also neeeeed '-I/usr/include', and '-I/usr/local/include'.

我错过了一个逗号,路径应该是./xxx,也neeeeed '-I/usr/include',和'-I/usr/local/include'