Visual Studio Code for ESP32 / ESP 8266 - a c_cpp_properties.json sample

Setting up Visual Studio Code for ESP32 / ESP 8266 development can be a bit awkward, if - like me - you don’t know exactly what’s happening behind the settings. The “C/C++ IntelliSense, debugging, and code browsing” plugin makes working with Visual Code a bit easier, but it needs to be configured for ESP projects. Luckily, that’s not too hard.

#include errors detected. Please update your includePath. 
Squiggles are disabled for this translation unit (/home/(etc) ).  
  
cannot open source file "freertos/FreeRTOS.h" (dependency of
"webserver.h")  
  
identifier "CONFIG\_WIFI\_SSID" is undefined

There are two things that need to be done: include the headers for the standard libraries, and include the defines.

Prerequisite: You need to have ESP-IDF installed and IDF_PATH defined. A quick way to check is to echo the path locally in a terminal window:

$ echo $IDF_PATH 
/home/yourusername/esp/esp-idf

Now, open Visual Studio Code:

$ code .

In VSC, go to the settings with ctrl-shift-p and select C/C++: Edit Configurations (json). Here, you’ll need to make the changes. Update the include path for ESP libraries and the compiled sdkconfig file. To do that, add these to the includePaths section (and add a comma after the previous entry):

"${env:IDF_PATH}/components/\*\*",
"${workspaceFolder}/build/include"

The final file will look something like this:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "${env:IDF_PATH}/components/**",
                "${workspaceFolder}/build/include"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

Save the settings file, and you should see a change in the warnings / errors right away. Note that none of these warnings effect the actual compilation of the code, it’s just in the editor. The settings will be saved in .vscode/c_cpp_properties.json within your project directory, in case you need to copy & paste them later.

Comments / questions

There's currently no commenting functionality here. If you'd like to comment, please use Twitter and @me there. Thanks!

Tweet about this - and/or - search for latest comments / top comments

Related pages