2

I am trying to configure my Visual Studio Code to developing C++ code on Linux Manjaro (last release), but I have a little bit of a problem.

enter image description here

Under the green line I had this description:

#include errors detected. Please update your includePath. IntelliSense features for this translation unit (/home/waski/myTest/myTest.cpp) will be provided by the Tag Parser. cannot open source file "stddef.h" (dependency of "iostream")

In c_cpp_properties.json file, section Linux, I have this config:

{
        "name": "Linux",
        "includePath": [
            "/usr/include/c++/7.1.1",
            "/usr/include/c++/7.1.1/x86_64-pc-linux-gnu",
            "/usr/local/include",
            "/usr/include",
            "${workspaceRoot}"
        ],
        "defines": [],
        "intelliSenseMode": "clang-x64",
        "browse": {
            "path": [
                "/usr/include/c++/7.1.1",
                "/usr/include/c++/7.1.1/x86_64-pc-linux-gnu",
                "/usr/local/include",
                "/usr/include",
                "${workspaceRoot}"
            ],
            "limitSymbolsToIncludedHeaders": true,
            "databaseFilename": ""
        }
    },

I also installed the c/c++ extension. In my opinion, includePath is fully complex, I have no idea, which patch is required also.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Robert Pawlak
  • 529
  • 7
  • 23

2 Answers2

2

I had exactly same problem today. Here's how I fixed it:

Find where on your system do you have stddef.h for example by running sudo find / -name stddef.h

Mine for example returns:

/usr/include/linux/stddef.h
/usr/lib/clang/4.0.1/include/stddef.h
/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/include/stddef.h

Pick any of these paths and add it to c_cpp_properties.json file, into includePath. You should be good to go then.

Lyarenei
  • 23
  • 1
  • 6
  • You really want to make sure to specify the *right* path to stddef.h, not just any of them. The wrong path will cause VSCode to read the wrong file, which can lead to inaccuracies and errors later on. My answer explains how to ensure you use the right path. – Scott McPeak Aug 31 '19 at 23:25
2

Your c_cpp_properties.json is missing the compilerPath attribute, so VSCode might be using the wrong compiler. To check, in the Command Palette (Ctrl+Shift+P), run "C/C++: Log Diagnostics". That will show the compiler path.

Also compare the output you see there to the output of:

  $ touch empty.c
  $ gcc -v -E -dD empty.c

At a minimum, you want the #include search paths to agree.

In this answer I have written up generic instructions on how to troubleshoot C++ compiler configuration in VSCode.

Scott McPeak
  • 8,803
  • 2
  • 40
  • 79