Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to specify the c++ standard of clangd without recompiling it?

I'm trying to use a feature in c++17(const lambdas) without having clangd error me. I've searched online and every answer tells me to recompile clangd with a flag. Is there truly no other way?

Edit: Clangd is not the compiler. It's a language server, which is a program made to be used with IDEs that basically checks your code for errors and warnings before compiling it. See https://clangd.llvm.org .

like image 591
Aaron Liu Avatar asked Nov 17 '25 03:11

Aaron Liu


1 Answers

Answer inspired by n. 1.8e9-where's-my-share m.

From https://clangd.llvm.org/config#compileflags:

You can create a config file for clangd. In the config file, you can specify the compiler options mimicked. For my question, do this:

CompileFlags:
  Add: [-std=c++20]

Put the configuration file as .clangd in a shared parent directory of the files you want this to apply to. If you want it to apply for the entire user, make it a config.yaml file in an OS-specific directory:

  • Windows: %LocalAppData%\clangd\config.yaml, typically C:\Users\Bob\AppData\Local\clangd\config.yaml.
  • macOS: ~/Library/Preferences/clangd/config.yaml
  • Linux and others: $XDG_CONFIG_HOME/clangd/config.yaml, typically ~/.config/clangd/config.yaml.
like image 147
Aaron Liu Avatar answered Nov 18 '25 18:11

Aaron Liu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!