简体   繁体   中英

Vim, C++, YCM, and Syntastic include path problems

I feel that I have an awesome setup for C++ programming using Vim but I can't find a way to tell Vim, YCM, and Syntastic where to search for headers. It would be really annoying to have to manually set the include path variables for Vim, YCM, and Syntastic every time I want to work on a project when this information exists in the Makefile. Is there any automated solutions for setting a global include path?

Edit: It won't even find the headers if I set the path like this ":set path = ".,/usr/include,include,../include,/home/steven/ovgl/include,,""

Your headers should appear in your tag files (see :h tags if you don't know about it).

Then YouCompleteMe is able to read the information about your headers from the tag file, as explained in the plugin faq :

YCM does not read identifiers from my tags files

First, put let g:ycm_collect_identifiers_from_tags_files = 1 in your vimrc.

Make sure you are using Exuberant Ctags to produce your tags files since the only supported tag format is the Exuberant Ctags format. The format from "plain" ctags is NOT supported. The output of ctags --version should list "Exuberant Ctags".

Ctags needs to be called with the --fields=+l (that's a lowercase L, not a one) option because YCM needs the language:<lang> field in the tags output.

NOTE: Mac OS X comes with "plain" ctags installed by default. brew install ctags will get you the Exuberant Ctags version.

Also make sure that your Vim tags option is set correctly. See :h 'tags' for details. If you want to see which tag files YCM will read for a given buffer, run :echo tagfiles() with the relevant buffer active. Note that that function will only list tag files that already exist.

You shold look for YCM-Generator . It is a script that generates ycm_extra_conf.py by running make and looking for all flags used. You run it once for project, and rerun only when make file changed.

I had faced a similar issue. I needed this for use with development using llvm. I solved it by following the below steps:

  1. Ctags -R --fields=+l * in your project/code base.
  2. In your user .vimrc file, add let g:ycm_collect_identifiers_from_tags_files = 1
  3. cp ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py ~/
  4. Add another line in .vimrc let g:ycm_global_ycm_extra_conf = '/home/<user>/ycm_extra_conf.py'
  5. reset terminal or hit bash

Note: You should start vim in the directory with the tags present in it. Or you may need to explicitly specify the directory where the tags are present.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM