Search code examples
cvisual-studio-codeinclude-pathset-include-path

Running C file in Visual Studio Code (Windows) without error - #include stdio.h cannot open source file


  1. How to run a C file in Visual Studio without:
    • having error message #include stdio.h cannot open source file; and
    • not download mingw for Visual Studio Code?

Solution

    1. Download Visual Studio Code & make sure you install C/C++ & C/C++ Extension Pack in extensions

    2. Go to Remote Explorer -> Select Connect to WSL (https://i.sstatic.net/fLVNw.png)

    3. Go to File -> Open Folder -> enter C directory /mnt/c

    4. Enter Ctrl + Shift + P -> Type configurations -> Select (UI) -> Enter /usr/bin/gcc in Complier Path

    5. Lastly, BE VERY SURE to set IntelliSenseMode to linux-gcc-x64 or any x64 compiler instead of x86 because x64 is for 32-bit compilers while x84 is for 64-bit compilers which gcc in Ubuntu workspace might not support. (https://i.sstatic.net/qT8zU.png)

    6. Voila! There should not be any squiggle lines afterwards.

    Please Vote this answer if it helped you!