C\C++ in VS Code with Linux Subsystem For Windows

♀尐吖头ヾ 提交于 2019-12-22 04:53:11

问题


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.

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 errors detected. Please update your includePath. IntelliSense features for this translation unit (C:\Users\Username\Source\c-lang\hello.c) will be provided by the Tag Parser. cannot open source file "stdio.h"

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
}

回答1:


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

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 -

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.



来源:https://stackoverflow.com/questions/50244620/c-c-in-vs-code-with-linux-subsystem-for-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!