对这种情况有更新的看法.在2018年期间,C++扩展向c_cpp_properties.json
文件的配置compilerPath
添加了另一个选项;
compilerPath
(可选)
用于生成项目的编译器的绝对路径.该扩展将查询编译器以确定用于IntelliSense的系统包含路径和默认定义.
如果使用includePath
,则不需要includePath
,因为IntelliSense将使用编译器来计算系统包含路径.
原来,
如何以及在何处在以下配置中添加包含路径?
列表是一个字符串数组,因此添加一个include路径看起来像;
"configurations": [
{
"name": "Mac",
"includePath": ["/usr/local/include",
"/path/to/additional/includes",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include"
]
}
]
来源cpptools blog 31 March 2016
链接的源代码有一个gif,显示Win32配置的格式,但其他配置也是如此.
The above sample includes the SDK (OSX 10.11) path if Xcode is installed
Note我发现一旦包含路径被更改,更新可能需要一段时间.
cpptools扩展名可以是found here.
有关VSCode中C++语言支持的更多文档(来自Microsoft)可以是found here.
为了保存(来自讨论),以下是任务内容的基本片段.JSON文件编译和执行C++文件或C文件.它们允许在文件名中使用空格(需要使用\"
转义json中的附加引号).shell as the runner使用,因此允许编译(clang...
)和执行(&& ./a.out
)程序.它还假设任务.json"存在"于本地工作区(在目录.vscode下).进一步的任务.json详细信息,例如支持的变量等,可以是found here.
对于C++;
{
"version": "0.1.0",
"isShellCommand": true,
"taskName": "GenericBuild",
"showOutput": "always",
"command": "sh",
"suppressTaskName": false,
"args": ["-c", "clang++ -std=c++14 -Wall -Wextra -pedantic -pthread \"${file}\" && ./a.out"]
}
对于C;
{
"version": "0.1.0",
"isShellCommand": true,
"taskName": "GenericBuild",
"showOutput": "always",
"command": "sh",
"suppressTaskName": false,
"args": ["-c", "clang -std=c11 -Wall -Wextra -pedantic -pthread \"${file}\" && ./a.out"] // command arguments...
}