Configure .ccls file for Vim

纵饮孤独 提交于 2021-01-28 03:13:08

问题


I have no idea what I am doing; I decided to use Vim as my only editor, I'm trying to set up autocompletion and syntax checking, so I need to configure a .ccls file in the root of my project (and I don't want to generate a compile_commands.json file so please don't tell me about it). But there is no detailed documentation whatsoever on .ccls because all it does is use compiler flags, which of course I don't know; I have started not too long ago in C++ and I don't know any CMake, I was used to just run my code from the IDE! I know that the default code to put in my .ccls is the path to my includes, which I do put (which are 5 paths that I get using clang++ -E -x c++ - -v < /dev/null) and I'm on mac btw. I put these, I get autocompletion, but my source breaks with errors telling things like iostream and every other header does not exist in "/usr/local/include" even though I provided 4 other paths (it really doesn't exit in /usr/local/include I don't know where iostream and those others are) and that I can't "cout << "Hello, World!" << endl" for example because ostream and char[] are incompatible and things like that. BTW even if I use compile_commands.json I still get errors it only fixes my header paths. Can someone just explain how to use .ccls? No links, just plain explanation. Or at least a default configuration to get me going.

P.S Do I also need to provide paths to my project's header files?

Edit: This is my .ccls

clang++
%cxx -std=c++17
%cxx -stdlib=libc++
%hxx --include=Global.h
%cxx -I/usr/local/include
%cxx -I/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
%cxx -I/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include
%cxx -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include
%cxx -I/Library/Developer/CommandLineTools/usr/include

回答1:


I may be wrong, but I would keep it simple and simply put these lines in the .ccls file

clang
-std=c++17
-stdlib=libc++
-isystem/usr/local/include
-isystem/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
-isystem/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include
-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include
-isystem/Library/Developer/CommandLineTools/usr/include

If it works with this at first, then you could prefix all these lines with %cxx %c -- well, -std=c++17, -stdlib=libc++ and ..../include/c++/v1 are just for C++ though.

BTW, I'm not sure if the first line shall be clang or clang++.

Note: I've used -isystem because of the following:

You can use -I to override a system header file, substituting your own version, since these directories are searched before the standard system header file directories. However, you should not use this option to add directories that contain vendor-supplied system header files; use -isystem for that. -- https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html



来源:https://stackoverflow.com/questions/63528459/configure-ccls-file-for-vim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!