更当前的情况。 2018年,C++扩展在c_cpp_properties.json文件的配置compilerPath中增加了另一个选项;
compilerPath(可选)
用于构建项目的编译器的绝对路径。该扩展将查询编译器以确定系统包含路径和用于 IntelliSense 的默认定义。
如果使用,则不需要includePath,因为 IntelliSense 将使用编译器来确定系统包含路径。
原来,
如何以及在哪里可以在下面的配置中添加包含路径?
列表是一个字符串数组,因此添加包含路径看起来像这样;
"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.
链接源有一个显示 Win32 配置格式的 gif,但同样适用于其他源。
如果安装了 Xcode,上述示例包括 SDK (OSX 10.11) 路径。
注意我发现一旦包含路径发生更改,更新可能需要一段时间。
cpptools 扩展名可以是found here。
关于 VSCode 中 C++ 语言支持的更多文档(来自 Microsoft)可以是 found here。
为了保存(来自讨论),以下是用于编译和执行 C++ 文件或 C 文件的 tasks.json 文件内容的基本 sn-ps。它们允许在文件名中使用空格(需要使用 \" 转义 json 中的附加引号)。外壳使用as the runner,从而允许程序的编译(clang...)和执行(&& ./a.out)。它还假设 tasks.json “存在”在本地工作区(在目录 .vscode 下)。进一步的 task.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...
}