xavierd / clang_complete

Vim plugin that use clang for completing C/C++ code.
http://www.vim.org/scripts/script.php?script_id=3302
1.95k stars 308 forks source link

It return "not found" when include another header. #156

Closed naive231 closed 12 years ago

naive231 commented 12 years ago

I build a .clang_complete in my project dir. My sources are in the same dir :

$project_root\ --- src01.cpp --- src02.cpp --- src01.h --- src02.h --- .clang_complete

.clang_complete has those content: -ID:\work\project\suffering_buster\code\project -ID:\svn\windows\tool\MinGW\include -ID:\svn\windows\tool\MinGW\lib\gcc\mingw32\4.5.2\include -ID:\svn\windows\tool\MinGW\lib\gcc\mingw32\4.5.2\include\c++

Then, given an example code like this: #include <vector> std:: <- It can show completion list. #include <src01.h> std:: <- It can't show completion list.

WHY ?

Silex commented 12 years ago

probably that src01.h contains invalid code that prevents clang from working.

naive231 commented 12 years ago

No! It isn't correct ! I build .clang_complete and it contains all information of completion of my symbol, it should find correct information despite I include any other nonsense headers. I am not compile any program, none any checking "error" should affect the search result. If symbol is in .clang_complete, it should be found after I use this plugin to find it.

Silex commented 12 years ago

No, your source is required to be compilable. If you include a header that doesn't compile, clang will stop there.

See https://github.com/Rip-Rip/clang_complete/blob/master/doc/clang_complete.txt?#L205-207

naive231 commented 12 years ago

compilable? You mean I should include all stuff that can pass compilation of my src01.cpp or src02.cpp ? I remember that I had try it before,it fails,too. But that's ok, I'll write another small project to test your solution. :)

Silex commented 12 years ago

Not really, what I meant is that in order to do completion, clang tries to compile your .cpp file and if it fails to do so then completion will not work.

naive231 commented 12 years ago

I upload an image about my files usage and put remarks. https://docs.google.com/open?id=0By2IiDMUu0gCN096TUxjTF9iZ2s

test.cpp at left view has two std:: code, upper can show completion menu,but lower can't.

.clang_complete in the center of view. I include lots of header. Of course, It contains .

Content of at the right side show its context of all includes, I believe all headers should be included by .clang_complete.

Well. test.cpp don't have any my project files any more, I just include some standard stuff like vector or string. But if I include , clang_complete always fail. If I include ,,,...some other standard stuff, clang_complete wouldn't fail anyway.

I can't tell differences about and the other standard stuff ?

Silex commented 12 years ago

The 2nd std:: cannot work because the first one creates a compile error. If you write std::string global_string; instead of the first one then the second one should work. The first one works because there's no errors before that point.

Anyway intermixing header inclusion with code is generally a bad idea, so avoid it.

naive231 commented 12 years ago

Oops,sorry for your misunderstanding. ;) My explanation about those two std:: are not exist at the same time, I just write them in codes for screen shot. If I just write the upper one std:: only, it can bring correct complete menu on, lower one std:: can't. So my question is that why can't I include would result to clang_complete fail ?

Silex commented 12 years ago

I have no clue, except that you intermix code with header inclusion which usually no one does.

@Rip-Rip: any idea?

xavierd commented 12 years ago

Does a file with just #include and an empty main, compile with clang? If it doesn't then look at the error, I'm guessing that one of the included headers contains some C++11 that is not supported by clang (if you're not using clang 3.1, you should try with it).

Other than that, I see that you're using header from gcc 4.5.2, and others from gcc 4.6.2, it shouldn't be a problem, but who knows…

naive231 commented 12 years ago

I'm using clang v3.2. If contains C++11 context really.... I can't use clang any more? It is standard library header and I wouldn't spend any time to modify its content ever. Final question is different version of header from different gcc version. I install MinGW from official site in that mean time, so I can't control its context,too. It shouldn't be a problem.

xavierd commented 12 years ago

If is using C++11, it may not work with clang: the set of C++ features supported by clang and gcc are different.

http://clang.llvm.org/cxx_status.html for clang, http://gcc.gnu.org/projects/cxx0x.html for gcc.

You didn't answer my first question: Does a file with just #include and an empty main, compile with clang?

naive231 commented 12 years ago

Yes, my code is just a empty main only, nothing more.