VSCode C++ 跨文件跳转失效
作者:zh_xuan
本文手把手教你通过安装C/C++扩展、开启CMake的compile_commands导出、并正确配置c_cpp_properties.json,彻底修复IntelliSense索引问题,感兴趣的可以了解一下
VSCode 搭配 CMake+MinGW 开发 C++,程序编译运行一切正常,但是 Ctrl 点击函数调用无法跳转定义。
1、安装微软官方 C/C++ 扩展 ms‑vscode.cpptools

2、CMake 开启导出编译数据库 CMAKE_EXPORT_COMPILE_COMMANDS

3、配置 .vscode/c_cpp_properties.json
原来是这样:
{
"configurations": [
{
"name": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "C:/Program Files (x86)/mingw64/bin/gcc.exe",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}改成:
{
"configurations": [
{
"name": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "C:/Program Files (x86)/mingw64/bin/g++.exe",
"cStandard": "c17",
"cppStandard": "c++23",
"intelliSenseMode": "windows-gcc-x64",
"compileCommands": "${workspaceFolder}/compile_commands.json"
}
],
"version": 4
}4、重载 VSCode 窗口,重建 IntelliSense 索引
Ctrl+Shift+P → Developer: Reload Window ,重载窗口

完成以上步骤,再次点击函数调用能跳转到函数定义处了。
到此这篇关于VSCode C++ 跨文件跳转失效的文章就介绍到这了,更多相关VSCode C++ 跨文件跳转内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
