C/C++ 扩展智能提示太慢或无法解析项目

问题

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
}
相关推荐
郝学胜-神的一滴7 分钟前
Qt OpenGL 生成Mipmap技术详解
开发语言·c++·qt·系统架构·游戏引擎·图形渲染·unreal engine
w-w0w-w20 分钟前
C++中vector的操作和简单实现
开发语言·数据结构·c++
Larry_Yanan20 分钟前
Qt安卓开发(一)Qt6.10环境配置
android·开发语言·c++·qt·学习·ui
橘颂TA23 分钟前
【剑斩OFFER】算法的暴力美学——力扣 227 题:基本计算机Ⅱ
c++·算法·leetcode·职场和发展·结构于算法
Z1Jxxx27 分钟前
整除整除整除
开发语言·c++·算法
dlpay30 分钟前
Visual Studio 2022中使用websocketpp
c++·ide·visual studio·boost·websocketpp
云雾J视界32 分钟前
从Boost的设计哲学到工业实践:解锁下一代AI中间件架构的密码
c++·人工智能·中间件·架构·stackoverflow·boost
CSDN_RTKLIB33 分钟前
【std::vector】resize元素处理方式
c++·stl
彩妙不是菜喵1 小时前
C++:类与对象
开发语言·c++
Yu_Lijing1 小时前
基于C++的《Head First设计模式》笔记——抽象工厂模式
c++·笔记·设计模式