On the YouCompleteMe Documentation, there are two options for setting up support for C/C++ semantic support. The first is using a compilation database with CMake (e.g. the file compile_commands.json) and the second is using a .ycm_extra_conf.py. Luckily, I am using Cmake so I am able to generate a compilation database. YouCompleteMe works ok for sources in my project however, it is not able to find headers for the following files: system headers (e.g. iostream) and it cannot find header files included in external projects in my project (i.e. git submodules in combination with with CMake ExternalProject_Add(...)). What wasn't clear for me from the documentation was whether or not I should use a combination of the ycm_extra_conf.py and the compile_commands.json. Can someone give me some advice on why my compilation database doesn't have sufficient information in it for me to find all the necessary header files?
Its been a while since I have actively used YCM, but from what I remember the ycm_extra_conf.py
can be used to add extra parameters to those found in the compile_commands.json
(maybe that is why its called "extra"?). In my Vim configuration folder I kept a ycm_extra_conf.py
-file and either created symbolic links to it or copied it to the project folders I had.
def FlagsForFile(filename, **kwargs):
return {
'flags': [
'-Wall',
'-Wextra',
'-Werror',
'-Wno-long-long',
'-Wno-variadic-macros',
'-fexceptions',
'-ferror-limit=10000',
'-DNDEBUG',
'-std=c99',
'-x', 'c',
'-D_GNU_SOURCE',
'-I.',
'-I', '/usr/include/'
],
'do_cache': True,
}
# vim:set et sw=4 ts=4 tw=120:
As you can see I have added '-I', '/usr/include/'
and depending on the project it could make sense to also add the path to the linux kernel header files or for c++ maybe something like /usr/include/c++/14.1.1/
(you package manager can help you finding these files, e.g. pacman -Ql gcc | grep iostream
)
If it does not work with the config you could also manually edit the compile_commands.json
, search for the file you are currently editing and modify the "command": "...
to add further include directories like -I /usr/include
. If only that works for you I will be happy to help to create some shortcut command to do that automatically for all files within compile_commands.json
© 2022 - 2024 — McMap. All rights reserved.