Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using json db for c++ completion headers do not compile #735

Closed
vadimstot opened this issue Dec 18, 2013 · 3 comments
Closed

When using json db for c++ completion headers do not compile #735

vadimstot opened this issue Dec 18, 2013 · 3 comments

Comments

@vadimstot
Copy link

I'm trying to make the completion work for headers. I'm doing the trick you've suggested where I replace the file name of the header and return the flags for the cpp file.
The problem is that for some reason the compilation fails because the clang is unable to find some basic headers like <string>, <cstring>, for example:
"col 10 error| 'cstring' file not found"

I suspect the the reason this happens to me is because my header and cpp are not located in the same directory though when I look at the flags returned by ycm_extra_conf.py they all have absolute path. Of course I don't just change the ".h" to ".cpp" but actually finding the right ".cpp" file. Not sure how this affects the compilation but just throw it out there.
I've installed the latest YCM and Clang a week ago (for the first time) so I should be up to date.

Thanks for all the work you do!

@Valloric
Copy link
Member

I think this is a duplicate of #303. Also, look at the current ycm_extra_conf.py in YCM; I made some changes to it recently to make it easier to get flags for headers when using the compilation db. If you based your extra conf file on old version, you might want to take some of the newer code.

@vadimstot
Copy link
Author

I did base it on the latest conf file.
I don't think that this is the same issue. I gave it a try anyway (added all the includes from "clang" with -isystem) and it didn't change anything.
Moreover the same error happens when I run with the same flags from the command like "clang -bla -bla ...".
Note this happens only on the header files of my project and not on the cpp files, i.e. dummy.cpp would compile but dummy.h (that also is included from dummy.cpp) would not.
Any ideas?

@Valloric
Copy link
Member

Well, the root of the issue is that the compilation database as produced by CMake doesn't have any flags for your header files, only source files. So you need to somehow produce flags for them. YCM's extra conf file has logic where it tries to detect whether the file that we need flags for is a header file and ask for flags for the corresponding source file instead since that would usually work. But this is not perfect and it was written to work for YCM code.

In the end, you need an extra conf file with logic relevant for your project. Either ensure that your compilation database has entries for header files or come up with some mechanism for producing flags for them in the extra conf file.

This is project specific; YCM works just fine if you give flags for headers.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants