15

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).

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.py to the TOP, meanwhile, I will generated tag and cscope file at TOP as well, therefore each time I open file on TOP, like:

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

to make sure each time I can add tag and cscope file 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:

#include <stdio.h>
#include <stdlib.h>
#include "math.h"
#include "common.h"
#include "debug.h"
#include "driver_ddi.h"
#include "driver.h"

the syntastic or YCM always show it can NOT find common.h and debug.h, other head files are OK.

My YCM and syntastic config part in vimrc file:

" 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.py write flags variable as:

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?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
How Chen
  • 1,340
  • 2
  • 17
  • 37
  • 2
    Again, try their issue tracker. – romainl Jan 09 '14 at 08:13
  • 1
    @romainl, I tried, but no reply – How Chen Jan 09 '14 at 09:13
  • What is the symptom when Syntastic cannot find the header files? – benjifisher Jan 09 '14 at 13:27
  • @benjifisher, just show can NOT file `xxx` head file in my location windows in VIM – How Chen Jan 10 '14 at 02:35
  • The `flags` variable is irrelevant. The return value of the `FlagsForFile` function is. How do you postprocess the flags? What does it return? Specifically, does it involve converting `-I` arguments to absolute paths (see [this function in ycm's own config](https://github.com/Valloric/ycmd/blob/master/cpp/ycm/.ycm_extra_conf.py#L118-L144))? – Jan Hudec Nov 12 '14 at 10:38
  • 1
    missing comma on the 4th line from the bottom – Tosha Nov 20 '14 at 23:18
  • @Tosha, after I add this comma, still doesn't work, the missing file exist in `../include`, not `../debug`, but anyway, thanks for pointing this error. – How Chen Jan 13 '15 at 08:40
  • Can you add a link to the issue on github? – Sardathrion - against SE abuse Jan 15 '15 at 10:04
  • Did you found anything? – Abhinav Gauniyal Feb 06 '15 at 17:45
  • @AbhinavGauniyal, not yet, still checking – How Chen Feb 09 '15 at 03:38
  • @HowChen , this is how I do it. First compile program using clang++ , not g++ and use cmake to export compilation database. Then set the absolute path to compilation database in your ycm_extra....conf. Most likely it will be the build directory , because compilation database changes each time you build with file/directory changes. – Abhinav Gauniyal Feb 09 '15 at 03:59
  • @AbhinavGauniyal, thanks for your comment, the problem is, on my SW work farm, it always use `gcc/g++` to compile the program, what is the main diff between `clang++` and `gcc` during compilation? – How Chen Feb 09 '15 at 04:28
  • YCM is clang dependent :) – Abhinav Gauniyal Feb 09 '15 at 04:49
  • @AbhinavGauniyal, yes, I know YCM need be compiled by `clang`, but the project or code I'm working on is not `clang` dependent, as I understanding is, after I compiled YCM, it should be used for my normal project, am I right? – How Chen Feb 09 '15 at 05:31
  • No , YCM still uses clang's compile flag to provide C++ autocomplete feature. that is why you need to build your project with clang. – Abhinav Gauniyal Feb 09 '15 at 09:12
  • 3
    if your .ycm_extra_conf.py is at top dir, you debug path should be ./debug, not ../debug. ycm use relative path base on the .ycm_extra_conf.py file path. – SolaWing Mar 17 '15 at 05:12
  • why dont you use a ycm-generator? you could try that and look what config file it outputs: https://github.com/rdnetto/YCM-Generator – hr0m Nov 22 '15 at 13:35

1 Answers1

8

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'.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203