问题
C/C++ 扩展不解析项目,导致源码中的变量、函数都为灰色状态,无法进行跳转。
有时候 log 会报如下错误:
Attempting to get defaults from C++ compiler in "compilerPath" property: 'D:/Development/Tools/mingw64/bin/gcc.exe'
Compiler info database not connected - skipping load.
Compiler query command line: D:/Development/Tools/mingw64/bin/gcc.exe -mlongcalls -fno-builtin-memcpy -fno-builtin-memset -fno-builtin-bzero -fno-builtin-stpcpy -fno-builtin-strncpy -fdiagnostics-color=always -fdiagnostics-color=always -ffunction-sections -fdata-sections -gdwarf-4 -ggdb -mdisable-hardware-atomics -Og -fno-shrink-wrap -fmacro-prefix-map=D:/Development/Workspace/esp32_workspace/xiaozhi-esp32=. -fmacro-prefix-map=C:/Users/ShiinaKaze/esp/v5.4/esp-idf=/IDF -fstrict-volatile-bitfields -fno-jump-tables -fno-tree-switch-conversion -std=gnu17 -m64 -Wp,-v -E -dM -x c nul
Failed to query compiler. Falling back to 32-bit intelliSenseMode.
Compiler query command line: D:/Development/Tools/mingw64/bin/gcc.exe -mlongcalls -fno-builtin-memcpy -fno-builtin-memset -fno-builtin-bzero -fno-builtin-stpcpy -fno-builtin-strncpy -fdiagnostics-color=always -fdiagnostics-color=always -ffunction-sections -fdata-sections -gdwarf-4 -ggdb -mdisable-hardware-atomics -Og -fno-shrink-wrap -fmacro-prefix-map=D:/Development/Workspace/esp32_workspace/xiaozhi-esp32=. -fmacro-prefix-map=C:/Users/ShiinaKaze/esp/v5.4/esp-idf=/IDF -fstrict-volatile-bitfields -fno-jump-tables -fno-tree-switch-conversion -std=gnu17 -m32 -Wp,-v -E -dM -x c nul
Failed to query compiler. Falling back to no bitness.
Compiler query command line: D:/Development/Tools/mingw64/bin/gcc.exe -mlongcalls -fno-builtin-memcpy -fno-builtin-memset -fno-builtin-bzero -fno-builtin-stpcpy -fno-builtin-strncpy -fdiagnostics-color=always -fdiagnostics-color=always -ffunction-sections -fdata-sections -gdwarf-4 -ggdb -mdisable-hardware-atomics -Og -fno-shrink-wrap -fmacro-prefix-map=D:/Development/Workspace/esp32_workspace/xiaozhi-esp32=. -fmacro-prefix-map=C:/Users/ShiinaKaze/esp/v5.4/esp-idf=/IDF -fstrict-volatile-bitfields -fno-jump-tables -fno-tree-switch-conversion -std=gnu17 -Wp,-v -E -dM -x c nul
[01m[Kgcc.exe:[m[K [01;31m[Kerror: [m[Kunrecognized command-line option '[01m[K-mlongcalls[m[K'
[01m[Kgcc.exe:[m[K [01;31m[Kerror: [m[Kunrecognized command-line option '[01m[K-mdisable-hardware-atomics[m[K'
原因
C/C++ 扩展用的语言服务器就是 clangd 的魔改,clangd 会先读取配置,然后再建立索引,这个过程需要一段时间。
如果右下角 language status 没有反应,前往 C/C++ 扩展的设置,将 logging level 调整为 debug 模式,方便查看 C/C++ 扩展运行情况。
c_cpp_properties.json
是一个很重要的文件,用于配置 C/C++ 扩展,所以按照要求填写,例如 ESP IDF 扩展自动生成的配置文件:
json
{
"configurations": [
{
"name": "ESP-IDF",
"compilerPath": "${config:idf.toolsPathWin}\\tools\\xtensa-esp-elf\\esp-14.2.0_20241119\\xtensa-esp-elf\\bin\\xtensa-esp32s3-elf-gcc.exe",
"compileCommands": "${config:idf.buildPath}/compile_commands.json",
"includePath": [
"${config:idf.espIdfPath}/components/**",
"${config:idf.espIdfPathWin}/components/**",
"${workspaceFolder}/**"
],
"browse": {
"path": [
"${config:idf.espIdfPath}/components",
"${config:idf.espIdfPathWin}/components",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}