Closed damiannmm closed 2 years ago
Working as intended on Ubuntu WSL, installed the ccls
via apt-get
,
$ sudo apt-get install ccls
Coding and compiling (with $ g++ -std=c++17 a.cpp
) shows no err nor warning on Ubuntu WSL.
$ ccls --version
ccls version 0.20190823.6-1~ubuntu1.20.04.1
clang version 10.0.0-4ubuntu1
$ which clang # returns nothing
$ g++ --version
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
...
#include <bits/stdc++.h>
is not standard C++, try using the standard headers.
Yes, and that's what I'm currently trying to make it work for. It worked fine on Ubuntu WSL but didn't on macOS. I even tried adding the header by make a softlink from Homebrew's gcc
of bits
dir to macOS' clang
, but it still didn't work.
$ ln -s /usr/local/Cellar/gcc/.../bits/ /Library/Developer/.../c++/v1/bits
Is there any way tweak the .ccls
so it uses the brew
's installed g++-12
instead of macOS' clang
? Or do I have to tweak it on NVIM's or coc
's settings?
I'm not sure what you mean by "use g++". ccls doesn't "use" any compiler per se. It's a separate program that parses C++ code to provide an LSP server. It could be written using an entirely stand-alone C++ parser but that would be a lot of duplication of effort, so instead ccls links in the clang project's C++ parser. This means that ccls parses content in the same way that clang does, but it doesn't really run the clang compiler that you have installed.
If you wanted a program that linked the C++ parser from the GCC compiler to parse your C++ code, instead of clang's, then that could be created (I don't know of one that exists today) but it would be a completely different project, not ccls.
If you are using non-standard header files, that the compiler you're using somehow knows how to find without you having to add -I
options to the compile line, then you have to tell ccls where to look for those directly by adding -I
options.
I'll try adding the -I
options as soon as I'm back on the cpp project. Let me know if I'm wrong, but that should be on the .ccls
file, right?
Thanks!
yes, its all explained in the wiki: https://github.com/MaskRay/ccls/wiki/Project-Setup#ccls-file
it should be something like:
%hpp
-isystem/path/to/bits/includedir
you can also put a stdc++.h
like header in your project and include it instead, like: https://gist.github.com/Tlapesium/d6b01ac194729799b35b2fb5a015ba95
I don't think you want to limit this to just header files via %hpp
do you?
yes, you are right, just remove the %hpp
but, I'd rather make a stdc++.h in my project, so its compatible with all compilers and standard c++, and you don't have to tell ccls where to look for it
(or just use the standard headers, avoiding compiling all std)
I think it's solved now; here's my .ccls
,
$ cat .ccls
clang
-isystem/Library/Developer/CommandLineTools/usr/include/c++/v1
-isystem/usr/local/Cellar/gcc/12.1.0/include/c++/12/x86_64-apple-darwin19
and voila, everything works as expected.
Thanks a lot to @madscientist and @FederAndInk!
Observed behavior
Doing
#include <bits/stdc++.h>
,scanf()
, andprintf()
shows err, despite it works without err when compiling; usingstd
as namespace also raises warning.I suspected that this happened because
ccls
usesclang
while I tried to compile withg++-12
; as of now, I still can't find out how to customizeccls
so it uses the binary that I wanted.Already tweaks
~/.ccls
andcompile_commands.json
to no avail.Expected behavior
There should be no err nor warning.
Steps to reproduce
$ brew install gcc ccls
$ vi a.cpp
with content similar to,$ g++-12 -std=c++17 a.cpp
gives no err.System information