Created
November 24, 2020 20:45
-
-
Save danngreen/9699fbc4471c547dc64104ea5f70f8b6 to your computer and use it in GitHub Desktop.
Makefile command to generate compile_commands.json with entries for c++ headers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Addresses an issue where language servers won't know what to do with header files | |
# since compile_commands.json typically only includes .cc/.cpp/.c files. | |
# | |
# Include this file from your main Makefile, or just paste the snippet in. | |
# To use: | |
# make compile_commands | |
# Requires bear and compdb | |
# bear [osx]: brew install bear | |
# compdb [see https://github.com/Sarcasm/compdb]: pip install compdb | |
# Assumes build files are in build/ and that `make all` builds the entire project | |
compile_commands: | |
rm -rf build | |
bear make -j16 all | |
compdb -p ./ list > compile_commands_with_headers.json 2>/dev/null | |
rm compile_commands.json | |
mv compile_commands_with_headers.json compile_commands.json | |
Update: Recent versions of clangd (12 and later) seem to work well without compdb. So, this is all that's needed:
compile_commands:
compiledb make
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It worked well
thnaks!