compile_commands.json文件是一个JSON格式的文件,它包含了编译器命令行选项和源文件之间的映射关系,用于许多代码编辑器和工具的代码补全、语法检查和代码导航等功能。
生成compile_commands.json文件的方法取决于你使用的编译器和构建系统。以下是一些常见的方法:
1 | cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON . |
1 2 3 4 5 | make --always-make --dry-run \ | grep -wE 'gcc|g\+\+|c\+\+' \ | grep -w '\-c' | sed 's|cd.*.\&\&||g' \ | jq -nR '[inputs|{directory:".", command:., file:match(" [^ ]+$").string[1:]}]' \ > compile_commands.json |
使用上述命令前需先安装jq软件。
1 | compiledb -n make -f /path/to/Makefile |
使用上述命令前需先安装compiledb软件。