VSCode中ESP-IDF里include文件冒红线显示找不到文件的解决方法之一
报错展示:
报错原因:
VS Code 的 C/C++ IntelliSense 没有正确拿到 ESP-IDF 的头文件路径。也就是工程中的c_cpp_properties.json中没有这些文件的路径。因此在其中添加上这些文件的路径就可以解决。但是相比继续手动补很多路径,更推荐直接让 VS Code 读取 ESP-IDF 的真实编译数据库。因为vscode虽然报错,但是仍然能正确编译烧录,说明我们实际上是有正确的编译数据库的。
解决方法:
compile_commands.json这个文件关联了所有的esp-idf的库函数。通过将c_cpp_properties.json关联上compile_commands.json文件,vscode就可以得到真是编译的数据库。
下面是我的c_cpp_properties.json文件内容
{ "configurations": [ { "name": "ESP-IDF", "compileCommands": "${workspaceFolder}/build/compile_commands.json", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "cStandard": "c17", "cppStandard": "gnu++17", "intelliSenseMode": "windows-gcc-x64" } ], "version": 4 }"compileCommands": "${workspaceFolder}/build/compile_commands.json"实现了将c_cpp_properties.json与compile_commands.json文件关联。
结果:
报错红线消失
