vscode includepath 设置自动搜索include
时间: 2023-09-21 10:11:33 浏览: 806
可以通过在 VS Code 中设置 C/C++ 扩展的 "includePath" 属性来自动搜索 include 文件。
1. 打开 VS Code,进入需要设置的 C/C++ 项目文件夹(即包含源代码的文件夹)。
2. 打开 .vscode 文件夹,如果没有则新建一个。
3. 在 .vscode 文件夹中创建一个名为 c_cpp_properties.json 的文件。
4. 在 c_cpp_properties.json 文件中添加以下代码:
```json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/include/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
```
在 "includePath" 属性中添加 "${workspaceFolder}/**",表示在项目文件夹及其所有子文件夹中搜索 include 文件。也可以添加其他路径,如 "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/include/**",表示在指定目录中搜索 include 文件。
5. 保存 c_cpp_properties.json 文件,重新打开 VS Code,C/C++ 扩展会自动搜索 include 文件。
注意:如果项目使用了 CMake 或者其他构建工具,需要在构建脚本中添加 include 路径,以确保编译器可以找到 include 文件。
阅读全文
相关推荐


















