Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
}
like image 293
loganhuskins Avatar asked May 09 '18 02:05

loganhuskins


People also ask

How add C compiler to VS Code?

Install Visual Studio Code. Install the C/C++ extension for VS Code. You can install the C/C++ extension by searching for 'c++' in the Extensions view (Ctrl+Shift+X). Install the Microsoft Visual C++ (MSVC) compiler toolset.

Can you write C in VS Code?

C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to enable cross-platform C and C++ development on Windows, Linux, and macOS.


1 Answers

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.

like image 81
loganhuskins Avatar answered Oct 10 '22 19:10

loganhuskins