8

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
}
loganhuskins
  • 1,399
  • 3
  • 15
  • 33

2 Answers2

8

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.

Azat Ibrakov
  • 9,998
  • 9
  • 38
  • 50
loganhuskins
  • 1,399
  • 3
  • 15
  • 33
  • Thank you :) do you happen to know what's the easiest way to configure the `launch.json` for debugging? – Davo Feb 26 '19 at 22:47
-1

I am new to C++ but the way I fixed this issue was to find all of my possible include paths by searching for stddef.h on my machine and then adding these to my includePath in VS code. These are the paths that were added:

C:\Cygwin\lib\gcc\x86_64-pc-cygwin\9.3.0\include

C:\Cygwin\lib\gcc\i686-w64-mingw32\9.2.0\include

C:\Cygwin\lib\gcc\x86_64-w64-mingw32\9.2.0\include

C:\Cygwin\usr\i686-w64-mingw32\sys-root\mingw\include

C:\Cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\include

C:\Cygwin\usr\include\c++\v1

C:\Cygwin\lib\gcc\i686-pc-cygwin\6.4.0\include

C:\Cygwin\lib\gcc\i586-pc-msdosdjgpp\5.4.0\include

C:\Cygwin\lib\gcc\i586-pc-msdosdjgpp\5.4.0\include-fixed

C:\Cygwin\usr\i586-pc-msdosdjgpp\sys-include

C:\Cygwin\lib\clang\8.0.1\include

C:\Cygwin\lib\clang\8.0.1\include