使用vim进行c项目开发时,使用Coc-Clangd作为语言服务器实现自动补全。当对项目结构进行调整后(.h和.c文件分离到了不同的目录),Coc-Clangd需要一定的配置才能找到相关的.h文件,否则会出现错误:
具体需要在项目根目录生成compile_commands.json
文件或者compile_flags.txt
文件:
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1
生成compile_commands.json
。make clean && bear make
即可生成compile_commands.json
。compile_flags.txt
文件参考2进行相关配置。