I have a C++ project consisting of multiple source and header files, and a Makefile to steer the build process. Building is done using clang++. Because I am not satisfied with the performance of the native C/C++ extension of VS code (although the codebase is quite small; ~5k lines, I cannot get completions instantaneously), I installed the clangd extension and set up a compile_commands.json
file. Completion, linting etc. works nicely, but I have constant difficulties jumping to symbols in other files:
- Jumping to symbol does not work if the file is not opened in VS Code;
- go to definition/implementation/declaration often jumps to a wrong spot, or does nothing, expecially when used on members of classes.
- symbols from other files often are not available for autocompletion.
How to I setup clangd correctly for my project?
My compile_commands.json
reads
[
{
"directory": "/.../",
"command": "clang++ -I/usr/local/include -I/usr/local/opt/libomp/include -std=c++2a -MT release/source.o -MMD -MP -MF release/source.d Wall -O3 -fopenmp -flto -DNDEBUG -c -o release/source.o source.cpp",
"file": "source.cpp"
},
...
]
for every source file in the project. Clangd reports no errors in the code, so it seems to read the compile commands.
I am using Homebrew clang++ and clangd version 15.0.7.