Vim, C++, YCM, and Syntastic include path problems
Asked Answered
L

3

12

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,,""

Leavis answered 3/8, 2013 at 0:35 Comment(2)
I imagine you could create a makefile target that would generate the YCM configuration from the makefile variables... never tested this, but a simple script could do the trick. Then for each new project you would include that target in the makefile, run make ycm_setup and you would be ready to code.Edo
It would be nice if you posted links to the plugins, or at least its full names (YouCompleteMe instead of YCM).Chun
C
3

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.

Chun answered 5/8, 2013 at 11:38 Comment(10)
I added the variable to my vimrc then I tried both "ctags -R * --fields=+l" and "etags -R * --fields=+l" but YCM does not seem to do anything with the tags.Leavis
Make sure you are using Exuberant Ctags. You could also check the setting of your 'tags' option, as noted on the last paragraph of the answer. YCM should consider the contents of 'tags', as it is stated on its FAQ; if you believe it is not, you should open an issue on the pluginChun
I don't actually understand why it is not working and so I won't be able to explain the issue if I open one. I've been trying for weeks to get YCM to work right so I just went back to clang_complete and supertab. sigh...Leavis
Did you check the ctags version and 'tags' option that I mentioned on my last comment? What about the output of :echo tagfiles(), which is part of the answer?Chun
/home/acgtyrant/Projects/caffe/src/caffe/net.cpp includes a head file caffe/common.hpp, but the actual position of the latter is /home/acgtyrant/Projects/caffe/include/caffe/common.hpp. Where should I execute ctags so that I use gvim to edit net.cpp and it does not complains that caffe/common.hpp' file not found?Graminivorous
Wow, two years later! Only two years to provide any feedback, @GraminivorousChun
@Graminivorous try the ctags documentation and vim help on the subject (:help tags).Chun
@Chun I solved it now, it is the problem of the .ycm_extra_conf.py actually.Graminivorous
Glad you figured it out @GraminivorousChun
@Graminivorous that link took me to survey about HIV/AIDSCoact
C
1

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.

Chapeau answered 22/3, 2017 at 9:10 Comment(0)
G
0

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.

Geraldina answered 10/2, 2015 at 1:33 Comment(1)
The YCM manual explicitly states that you should change the configuration file and not just use the provided example.Queer

© 2022 - 2024 — McMap. All rights reserved.