Search code examples
cvisual-studio-codeheader-fileswindows-subsystem-for-linux

Error in VSCode for Windows using Linux header


I'm using VS Code on Windows 10 and have written some C code. In the code, I need to use the sys/wait.h header. Since that is a Linux-specific header, I need to compile and run with WSL2 using Ubuntu as a subsystem.

The code compiles and works with WSL but VS Code gives me the following error:

#include errors detected. Please update your includePath.

My guess is it's because my current includePath points to GCC on my Windows machine and not to WSL, which is why it can't find this header. Is there a way for me to also include the headers found in WSL Ubuntu or do I have to live with this annoying error?


Solution

  • To use the WSL/Linux gcc and Linux headers/libraries from within VSCode::

    1. Install either the "WSL - Remote" extension or the "Remote Development" extension pack in VSCode.
    2. Either:
      • From within WSL, cd to your project directory and then start VSCode with code ..
      • Start VSCode from Windows and click the "Open a Remote Window" button at the bottom left of the screen. It looks like a > < stacked together. Then select "Open Folder in WSL ...". This is also available from the Command Palette (Shift+Ctrl+P) with "Remote WSL - Open Folder in WSL ..."