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

Use completions from C header files in C++ projects #312

Closed
jchnkl opened this issue May 9, 2013 · 6 comments
Closed

Use completions from C header files in C++ projects #312

jchnkl opened this issue May 9, 2013 · 6 comments

Comments

@jchnkl
Copy link

jchnkl commented May 9, 2013

If I have C++ file, YCM works well for std:: etc. (in general cpp headers), but when I use a header which is basically a C header wrapped in extern "C" I don't get any completions.
Does this generally not work or am I just missing some configuration?

@Valloric
Copy link
Member

Please provide a testcase.

@jchnkl
Copy link
Author

jchnkl commented May 10, 2013

Go to cpp/ycm/ClangCompleter. Open a file test.cpp and insert

#include <clang-c/CXCompilationDatabase.h>

int main( int argc, char ** argv )
{
   // try to complete e.g. clang_CompilationDatabase_fromDirectory
   return 0;
 }

Note that the above example already fails for the #include completion for me. Completing C functions, like the clang_* ones does not work either.

[Update]
I tried it with a vanilla vim setup, no other plugins, despite YCM. Same result. The only thing that works is file name completion when I type #include ".

[Another Update]
Ok, I figured out that I can trigger the completion anywhere using Ctrl-Space. However, I still do not have completion for standard header files, e.g. iostream or after std::. I've appended '-isystem', '/usr/include' to the flags but it doesn't seem to help.

[More Updates]
I observed this behaviour (this is not quite true, see below).
When '-isystem', '/usr/include/c++' is added to flags, I get completion for std::.
For '-isystem', '/usr/include/c++/4.7.2', file names like iostream get completed, but not std::.
If I put both paths in flags, it's the same as in the latter case.

Sometimes it works, sometimes not. I'm having std:: completion only with '-isystem', '/usr/include', but still lack file name completion for std headers. Sometimes means: when I'm starting a function which has no closing brace yet, completion does not work. After adding the closing brace, completion works.

Now I've tried adding #include <xcb/xcb.h>. No matter if I have /usr/include/xcb in flags or not or if I'm pressing Ctrl-Space, I do not get completions for xcb_*.

Also, if I start with a plain, empty file, there is no comletion for keywords like include, int, void, etc.
Any chance to get reasonable stdlib + keyword completion?

@pedrovanzella
Copy link

Look at #303 for std:: completion.

@jchnkl
Copy link
Author

jchnkl commented May 16, 2013

@pedrovanzella Thank you!

@Valloric
Copy link
Member

The std:: completion part sounds like issue #303, so I'm closing this issue as a duplicate of that one.

There's no keyword completion in YCM. Issue #142 tracks that.

@akirayu101
Copy link

closed? how do you got that problem solved plz?

bijancn pushed a commit to bijancn/YouCompleteMe that referenced this issue Jul 26, 2016
Add --sysroot and -gcc-toolchain as INCLUDE_FLAGS

Hello,

I use YCM in a cross compiled project.
To compile the project we use '--sysroot' and '-gcc-toolchain' these directories were removed from the compiling commandline and resulted in build fails.
Therefore I added those to the INCLUDE_FLAGS.

Greetings,
Nagua

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/312)
<!-- Reviewable:end -->
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants