Visual Studio代码includePath [英] Visual Studio Code includePath

查看:387
本文介绍了Visual Studio代码includePath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Visual Studio Code中构建C / C ++。我安装了C / C ++及其所有相关扩展。

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\n");
    return 0;
}

但是 #include< stdio.h> 说添加包含设置的路径。当我单击它时,它将移至 c_cpp_properties.json。

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"]
    }
]


推荐答案


如何在以下配置中以及在何处添加包含路径?

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"
        ]
    }
]

来源; cpptools博客2016年3月31日

链接的源中有一个gif,用于显示Win32配置的格式,但其他情况也是如此。

The linked source has a gif showing the format for the Win32 configuration, but the same applies to the others.

如果安装了Xcode,以上示例将包含SDK(OSX 10.11)路径

注意我发现更改包含路径后可能需要一段时间才能更新。

Note I find it can take a while to update once the include path has been changed.

cpptools扩展名可以为在此处找到

The cpptools extension can be found here.

有关Microsoft的其他文档可以在此处找到

Further documentation (from Microsoft) on the C++ language support in VSCode can be found here.

在2018年期间,C ++扩展为配置 c_cpp_properties的ools / blob / master / Documentation / LanguageServer / c_cpp_properties.json.md rel = noreferrer> compilerPath 。 json 文件;

During 2018, the C++ extension added another option to the configuration compilerPath of the c_cpp_properties.json file;


compilerPath (可选)
用于构建项目的编译器的绝对路径。扩展名将查询编译器,以确定系统包含路径和默认定义以用于IntelliSense。

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.

如果使用,则<$ c不需要$ c> includePath ,因为IntelliSense将使用编译器找出系统包含路径。

If used, the includePath would not be needed since the IntelliSense will use the compiler to figure out the system include paths.

为了保留(出于讨论目的),以下是用于编译和执行C ++文件或C文件的task.json文件内容的基本摘要。它们允许在文件名中留空格(要求使用 \ 在json中转义额外的引号)。shell用于作为跑步者,从而允许进行编译( clang ... )和执行(&& ./a.out )。它还假定task.json存在于本地工作区(在目录.vscode下)。task.json的详细信息(例如受支持的变量等),可以在此处找到

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.

对于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... 
}

这篇关于Visual Studio代码includePath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆