Visual Studio Code, #include lt;stdio.hgt; saying quot;Add include path to settingsquot;(Visual Studio 代码,#include stdio.h说“向设置添加包含路径)
问题描述
我正在尝试在 Visual Studio Code 中构建 C/C++.我安装了 C/C++ 和所有相关的扩展.
#include int main() {printf("现在测试C
");返回0;}
但是在 #include <stdio.h> 下有一条绿线,上面写着向设置添加包含路径".当我点击它时,它会移动到c_cpp_properties.json".
我如何以及在哪里可以在下面的配置中添加包含路径?
配置":[{"name": "Mac","includePath": ["/usr/include"]}]
对这种情况的最新看法.2018 年,C++ 扩展在配置中添加了另一个选项 c_cpp_properties.json文件的>compilerPath
;
compilerPath
(可选)用于构建项目的编译器的绝对路径.该扩展将查询编译器以确定用于 IntelliSense 的系统包含路径和默认定义.
如果使用,则不需要 includePath
,因为 IntelliSense 将使用编译器找出系统包含路径.
原来,
<块引用>我如何以及在哪里可以在下面的配置中添加包含路径?
列表是一个字符串数组,因此添加一个包含路径看起来像;
配置":[{名称":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 博客 2016 年 3 月 31 日.
链接的源有一个 gif,显示了 Win32 配置的格式,但同样适用于其他配置.
如果安装了 Xcode,上面的示例包括 SDK (OSX 10.11) 路径.
注意我发现更改包含路径后可能需要一段时间才能更新.
cpptools 扩展可以在在这里找到.
有关 VSCode 中 C++ 语言支持的更多文档(来自 Microsoft)可以在此处找到.
为了保存(来自讨论),以下是tasks.json文件内容的基本片段,用于编译和执行C++文件或C文件.它们允许文件名中有空格(需要使用 "
转义 json 中的额外引号).shell 被用作作为运行器,从而允许编译(clang...
)和程序的执行 (&& ./a.out
).它还假定tasks.json存在".在本地工作区中(在目录 .vscode 下).更多 task.json 详细信息,例如支持的变量等,可以在此处找到.>
对于 C++;
<代码>{版本":0.1.0",isShellCommand":真,taskName":GenericBuild",showOutput":总是",命令":sh",suppressTaskName":假,"args": ["-c", "clang++ -std=c++14 -Wall -Wextra -pedantic -pthread "${file}";&&./a.out"]}
对于 C;
<代码>{版本":0.1.0",isShellCommand":真,taskName":GenericBuild",showOutput":总是",命令":sh",suppressTaskName":假,args":[-c",clang -std=c11 -Wall -Wextra -pedantic -pthread "${file}";&&./a.out"]//命令参数...}
I'm trying to build C/C++ in Visual Studio Code. I installed C/C++ and all the relevant extensions.
#include <stdio.h>
int main() {
printf("Test C now
");
return 0;
}
But there's a green line under #include <stdio.h>
saying "Add include path to settings". When I click it, it moves over to "c_cpp_properties.json".
How and where can I add include paths in the configurations below?
"configurations": [
{
"name": "Mac",
"includePath": ["/usr/include"]
}
]
A more current take on the situation. During 2018, the C++ extension added another option to the configuration compilerPath
of the c_cpp_properties.json
file;
compilerPath
(optional) The absolute path to the compiler you use to build your project. The extension will query the compiler to determine the system include paths and default defines to use for IntelliSense.
If used, the includePath
would not be needed since the IntelliSense will use the compiler to figure out the system include paths.
Originally,
How and where can I add include paths in the configurations below?
The list is a string array, hence adding an include path would look something like;
"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"
]
}
]
Source; cpptools blog 31 March 2016.
The linked source has a gif showing the format for the Win32 configuration, but the same applies to the others.
The above sample includes the SDK (OSX 10.11) path if Xcode is installed.
Note I find it can take a while to update once the include path has been changed.
The cpptools extension can be found here.
Further documentation (from Microsoft) on the C++ language support in VSCode can be found here.
For the sake of preservation (from the discussion), the following are basic snippets for the contents of the tasks.json file to compile and execute either a C++ file, or a C file. They allow for spaces in the file name (requires escaping the additional quotes in the json using "
). The shell is used as the runner, thus allowing the compilation (clang...
) and the execution (&& ./a.out
) of the program. It also assumes that the tasks.json "lives" in the local workspace (under the directory .vscode). Further task.json details, such as supported variables etc. can be found here.
For 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"]
}
For 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...
}
这篇关于Visual Studio 代码,#include <stdio.h>说“向设置添加包含路径"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Visual Studio 代码,#include <stdio.h>说“向设置添
基础教程推荐
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01