VS Code 中的 C\C++ 与适用于 Windows 的 Linux 子系统 [英] C\C++ in VS Code with Linux Subsystem For Windows

查看:29
本文介绍了VS Code 中的 C\C++ 与适用于 Windows 的 Linux 子系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用适用于 Windows 的 Linux 子系统的 Windows 10 build 17134 上的 VS Code 编辑器中使用包含"时遇到问题.我安装了 C/C++ 扩展,可以使用文档 这里.

I am having issues getting my "includes" to work in my editor in VS Code on Windows 10 build 17134 using Linux Subsystem for Windows. I have the C/C++ extension installed and can run my application using the launch.json information outlined in the documentation here.

在他们的文档这里,微软概述了如何设置一个 c_cpp_properties.json 来解决这个问题,但它并没有让我进步多少.目前,我在包含"行下收到一条错误消息:

In their documentation here, Microsoft outlines how to set up a c_cpp_properties.json to get around this issue, but it has not advanced me much. Currently, I am getting an error under my "includes" line which says:

#include 检测到错误.请更新您的包含路径.此翻译单元 (C:\Users\Username\Source\c-lang\hello.c) 的 IntelliSense 功能将由标签解析器提供.无法打开源文件stdio.h"

我的 c_cpp_properties.json:

My c_cpp_properties.json:

{
    "configurations": [
         {
             "name": "WSL",
             "intelliSenseMode": "clang-x64",
             "compilerPath": "/usr/bin/gcc",
             "includePath": [
                 "${workspaceFolder}",
                 "/usr/include/"
             ],
             "defines": [],
             "browse": {
                 "path": [
                     "${workspaceFolder}",
                     "/usr/include"
                 ],
                 "limitSymbolsToIncludedHeaders": true,
                 "databaseFilename": "",
             },
             "cStandard": "c11",
             "cppStandard": "c++17"
         }

    ],
    "version": 4
}

推荐答案

感谢 this 对 Github 问题的评论.

Figured it out thanks to this comment on a Github issue.

我采用了他们推荐的命令并对其进行了编辑以使用 C 而不是 C++,并在 WSL 中运行它:

I took the command they recommended and edited it to use C and not C++ and ran it in WSL:

gcc -v -E -x c -

它列出了所有 gcc 正在寻找 C 库的地方,等等.我复制了该列表并将各个路径放在includePath"和path"数组中.这是我更新的 c_cpp_properties.json 文件:

It listed where all gcc was looking for C libs, among other things. I copied that list and put the individual paths in the "includePath" and "path" arrays. Here is my updated c_cpp_properties.json file:

{
  "configurations": [
    {
      "name": "WSL",
      "intelliSenseMode": "clang-x64",
      "compilerPath": "/usr/bin/gcc",
      "includePath": [
        "${workspaceFolder}",
        "/usr/include/x86_64-linux-gnu/5/include",
        "/usr/local/include",
        "/usr/include/x86_64-linux-gnu/5/include-fixed",
        "/usr/include/x86_64-linux-gnu",
        "/usr/include"
      ],
      "defines": [],
      "browse": {
        "path": [
          "${workspaceFolder}",
          "/usr/include/x86_64-linux-gnu/5/include",
          "/usr/local/include",
          "/usr/include/x86_64-linux-gnu/5/include-fixed",
          "/usr/include/x86_64-linux-gnu",
          "/usr/include"
        ],
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""
      },
      "cStandard": "c11",
      "cppStandard": "c++17"
    }
  ],
  "version": 4
}

希望这对某人有所帮助.

Hope this helps someone.

这篇关于VS Code 中的 C\C++ 与适用于 Windows 的 Linux 子系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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