6

I have started to learn c, I tried to use it with VS Code, but the #include < stdio.h> is highlighted in green with this error message:

#include errors detected. Please update your includePath. IntelliSense features for this translation unit
(C:\Users\Jerlam\Desktop\C\training\dweight.c) will be provided by the
Tag Parser.

could not open source file "stdio.h" (no directories in search list)

I have seen some topics about this issue, but none of them helped me to fix it.
Here is my c_cpp_properties.json file in which I have to add the path (of stdio). In fact the documentation about it is absolutely not beginner friendly.

    {
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
        ],
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

I have added manually this path:

"C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt"

because it contains the stdio.h header.

What shall I do? Thanks.

CKE
  • 1,533
  • 19
  • 18
  • 29
Jerlam
  • 943
  • 2
  • 12
  • 31
  • Since you're using the mingw-w64 compiler, I would assume that the correct version of `stdio.h` would be the one in `c:\\mingw-w64\\include`? I know nothing about Windows or VS, but that looks wrong to me. – Lee Daniel Crocker Aug 16 '18 at 19:49
  • Ups sorry, I added myself this line of code that I took from another post. This line is not there originally. I installed mingw, but it turns out that there is no include folder in C:/mingw/ ... – Jerlam Aug 16 '18 at 21:07
  • 1
    Does compiling the project work or does it also fail? – Gerhardh Aug 17 '18 at 11:16

4 Answers4

8

I have found the solution thanks to this video on how to Set Up C++ Development With Visual Studio Code on Windows 10 (VS Code).

  1. I launched MinGW Installation Manager and installed all the package from the Basic Setup.

  2. I added the path of the gcc compiler to my system´s environment variables: C:\MinGW\bin, in which is the gcc.exe.

  3. I opened the c_cpp_properties.json file and added different paths for the folders I want to include. So now my c_cpp_properties.json file looks like this:

    {
        "configurations": [{
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.10240.0\\ucrt",
                "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\include",
                "C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0",
                "C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include\\c++",
                "C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include"
            ],
            "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
            "intelliSenseMode": "clang-x64"
        }],
        "version": 4
    }
    
KyleMit
  • 30,350
  • 66
  • 462
  • 664
Jerlam
  • 943
  • 2
  • 12
  • 31
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/20613793) – Dov Benyomin Sohacheski Aug 17 '18 at 10:35
  • @DovBenyominSohacheski I am sorry, I am not completly used to stackoverflow. My solution was edited. – Jerlam Aug 17 '18 at 13:09
  • regarding this statement: `#include < stdio.h>` This does not have the proper syntax. There should be no spaces between the `<` nor `>` and the name of the header file – user3629249 Aug 17 '18 at 22:06
  • @user3629249 I put a space because otherwise it does not display anything, I don't know why... – Jerlam Aug 20 '18 at 08:15
2

(Updated the answer)

Anyone else coming here, note VS Code keeps caches. If even after making changes to your c_cpp_properties.json the error doesn't go away. Try deleting the cache for your workspace (aka directory).

For,

Windows: C:\Users\<YOUR_USER_NAME>\AppData\Roaming\Code\CachedData\*

Linux:

Insane
  • 31
  • 4
  • I think that may have fixed it... Thanks... By the way, the VSCode setting for the IntelliSense path is `C_Cpp.intelliSenseCachePath`. (On Linux, I navigated into it, found a folder named `/ipch/`, and ran `sudo rm -r ipch`.) – Andrew Jan 26 '21 at 02:39
2

Worked for me, running VSCode on Windows 10.

  1. Go to your project folder
  2. Open .vscode subfolder
  3. Go to c_cpp_properties.json
  4. Replace everything you have in that file with this code:
{
"configurations": [
    {
        "name": "MinGW",

        "includePath": [
            "${workspaceFolder}"
        ],
        "defines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ],
        "intelliSenseMode": "clang-x64",
        "browse": {
            "path": [
                "${workspaceFolder}"
            ],
            "limitSymbolsToIncludedHeaders": true,
            "databaseFilename": ""
        },
        "cStandard": "c11",
        "cppStandard": "c++17"
    }
],
"version": 4
}
  1. Save and restart the IDE.
Dennis Kozevnikoff
  • 2,078
  • 3
  • 19
  • 29
0

It may happen if you have visual studio and code together on your pc. Just try to uninstall all C and C++ extensions from apps list, visual studio and visual studio code on your pc then restart and again install the vs code. I wasted my whole day behind it but no JSON file did work for me. you only need to put the MinGW-64/bin path in JSON file on vs code where ever you have installed the MinGW-64 on your pc. if you do not have MinGW on your pc I am putting a video link

https://www.youtube.com/watch?v=0HD0pqVtsmw

Sampat Aheer
  • 57
  • 1
  • 10