Hi everyone,
I'm a big fan of Visual Studio Code. However, I'm not a big fan of the C/C++ intellisense provided by Microsoft. Although I am aware it works on other machines; on my machine, it is a slow and buggy extension that seems to hallucinate more often than not, which led me to switch to clangd as my primary C/C++ autocomplete extension. I've been using clangd for quite a while and I like it. One annoying thing I want to fix though, is the lack of inclusion of headers that are provided by GCC.
Headers like bits/stdc++.h, ext/pb_ds aren't supported by clang, but I would like to know how I could be able to use these headers with clangd on vscode. I remember that during IOI2024, the clangd extension provided by the host allowed me to use these headers, so I know that it is possible.








Auto comment: topic has been updated by kunzaZa183 (previous revision, new revision, compare).
I did someting similar for my non vscode setup. My understanding is that clangd uses a clang/clang++ binary to parse and understand code. After you find that binary you can try "/your/clang/location/clang++ -v foo.cpp" to figure out the exact include paths of clang++. Once you find those paths you should manually add the headers you want to use.
You can configure clangd to additionally use GCC’s header search paths as follows:
Make clangd use the
--query-driver=<globs>flag, where<globs>is a comma-separated list of globs at least one of which matches theg++you want to use (see https://clangd.llvm.org/guides/system-headers#query-driver). You can probably set this option in VS Code’s settings for the clangd extension. I use ST4, on macOS, so I use"initializationOptions": { "clangd.query-driver": "/opt/homebrew/bin/gcc-*,/opt/homebrew/bin/g++-*" }in myLSP-clangd.sublime-setingsfile to tell clangd to use the search paths of my Homebrew installation of GCC.Then in your
.clangdfile, setCompiler(underCompileFlags) to the path of a G++ that matches the glob you used with--query-driver(see https://clangd.llvm.org/config#compiler). E.g., I useg++-14.I have found this method to be the only way to make clangd recognize the
<bits/…>headers on macOS. Manually adding the location of the parent directory ofbits/stdc++.hwith-isystem<path>did not work for me.Thank you so much!!!
If someone is trying to do the same on VSCode then follow these steps:
Step 1: Install gcc/g++ using homebrew Step 2: Edit VSCode Settings (either in JSON or UI):
Step 3: Make a global ~/.clangd or in the current folder: and paste the following contents (change the g++ version depending what's installed)