在Visual Studio Code中编译C/C代码时,您可能会在#include 下遇到一个绿色行,以指示“添加路径”。 This guide will delve into the solution, exploring how to specify include paths in the Visual Studio Code configurations.
Adding Include Paths to Configurations
Locate the "c_cpp_properties.json" File:
Navigate to your project's directory and look for the .vscode folder.在此文件夹中,您会找到“ C_CPP_PROPERTIES.JSON”文件。
打开“ c_cpp_properties.json”文件,并查找“配置” array array。在此数组中,您可以指定不同配置的路径,例如“ MAC”,如下所示:- “ configurations”:[
{
“名称”:“ Mac”,
“ includepath”:[“/usr/include”]
}
] 以添加附加include路径,只需将它们包含在“ IncludePath”数组作为字符串中即可。用逗号将每个路径分开。例如,要添加“ my_include”目录,更新的配置将是: [griendionurations':[
{
“名称”:“ Mac”,
“ includepath”:[/usr/include“,”/my_include”]
}
]
利用“ CompilerPath”选项- 现在在Visual Studio Code中的C扩展名现在提供一个可选的“ CompilerPath”字段中的“ C_CPP_PROPERTIES”。设置时,扩展程序将查询指定的编译器以确定系统包括路径,默认的IntelliSense定义。用于编译和执行C或C代码,请考虑使用Tasks.json文件,该文件提供了一种方便的方法来定义自定义构建并在Visual Studio代码中运行命令。