[Help wanted]: can I use g++ with clangd? reddit / emacs ---------------------------------------------------------------------- Financial-Bet2253 · 2022-11-14 14:09 I use lsp-mode && c++. For some reason, my project can only built with g++. But I use clangd as lsp server. I found that there's a parameter called "query-driver", would it take effect if I use g++ as query driver? What's more, in compile_commands.json file, I replace the compiler clang++ with g++, will it bother? ---------------------------------------------------------------------- yyoncho · 2022-11-14 15:16 I would ask that question in clangd's discord channel. ---------------------------------------------------------------------- CorysInTheHouse69 · 2022-11-14 16:26 Yes you can. They are not mutually exclusive ---------------------------------------------------------------------- yapfff · 2022-11-14 16:29 I use clangd with gcc (not g++, but same toolchain) every day in an embedded context. It works fine. clangd is supposed to adapt itself to the compiler used as defined in the compilation database (compile_commands.json). In an embedded context, I had an issue with a gcc option clangd didn't understand. You can deal with this easily using a `.clangd` configuration, mine contain for example: CompileFlags: Remove: -f* This remove all the optimization options (including the problematic one), the ones starting with "-f". They're not useful for LSP functions and some may be problematic. But overall the clang and clangd have very good compatibility with the GCC toolchain. Hope that helps, if it's really C++ specific there may be other "gotcha" I don't know about. ---------------------------------------------------------------------- ForkInBrain · 2022-11-14 17:37 > But I use clangd as lsp server. That is fine, but know that the warnings, errors, etc., the LSP generates will come from clang. It will not run gcc. > I found that there's a parameter called "query-driver", would it take effect if I use g++ as query driver? This is only about asking gcc where the system headers are, so clangd can find them. See https://clangd.llvm.org/guides/system-headers > What's more, in compile_commands.json file, I replace the compiler clang++ with g++, will it bother? clangd will ignore that change completely and always use itself as the "compiler". ---------------------------------------------------------------------- Financial-Bet2253 · 2022-11-15 02:07 Thanks. You said "I had an issue with a gcc option clangd didn't understand", what does it mean? Will clangd report some error? ---------------------------------------------------------------------- Financial-Bet2253 · 2022-11-15 02:08 Perfect answer! So clangd just ignore my g++ compiler🤣 ---------------------------------------------------------------------- yapfff · 2022-11-15 12:45 It was quite some time ago and I forgot the specifics... But I had to add this filtering clangd configuration to get a smooth operation. ---------------------------------------------------------------------- Thaodan · 2022-11-15 21:03 Yeah probably also ignores any GCC ism's. ---------------------------------------------------------------------- Thaodan · 2022-11-15 21:04 I wouldn't advice discord with all the privacy issues. The IRC or Matrix channel would be better I think. ---------------------------------------------------------------------- yyoncho · 2022-11-15 21:41 Do they have irc/matrix channels? ---------------------------------------------------------------------- Financial-Bet2253 · 2022-11-16 02:41 i have one more question. If i don't have clang && clang++ installed, how could clangd use clang? ---------------------------------------------------------------------- Thaodan · 2022-11-16 08:21 You can't clangd depends on clang. ---------------------------------------------------------------------- Financial-Bet2253 · 2022-11-16 08:24 I mean if there's only gcc&&g++ on my linux system, how could clangd provide the functionality like semantic checking? ---------------------------------------------------------------------- Thaodan · 2022-11-16 20:11 You can't clangd depends on libclang.