Compiled code in VS code still get library include error

Hi,

I struggled to get the VS code to work and compile my ESP32 code. I did the following:

  1. Downloaded Arduino compiler extension.
  2. Added C/C++ extension.
  3. Setup the compiler/libraries path.
  4. Solved all include issues.

It worked but still I get a library include error:

[Starting] Verifying sketch 'tft_espi.ino'
[Warning] Output path is not specified. Unable to reuse previously compiled files. Build will be slower. See README.
E:\projects_electronics_programming\tft\tft_espi\tft_espi.ino:3:10: fatal error: TFT_eSPI.h: No such file or directory
#include <TFT_eSPI.h>
^~~~~~~~~~~~
compilation terminated.
Error during build: exit status 1
[Warning] Failed to generate IntelliSense configuration.
[Error] Verifying sketch 'tft_espi.ino': Exit with code=1

I'm including all the libraries in the main source file, the code is compiled ok in the Arduino IDE perfectly:

#include <SPI.h>
#include <Wire.h>
#include <TFT_eSPI.h>
#include <PNGdec.h>
#include <Adafruit_PWMServoDriver.h>
#include <stepper_dev_prj.h>
#include "system_variables.h"
#include "task_manager.ino"
#include "ui_tools.ino"
#include "control_page.ino"

TFT_eSPI tft = TFT_eSPI();
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

void setup(void) {
  // serial & communication setting
//  Serial.begin(9600);
//  Serial.println("\n\nStarting...");  // for ESP32, not for STM32 over ST-Link
//  ets_printf("isr setup\n");          // for ESP32, can be used inside ISR

  // pwm setup
  pwm.begin();
  // pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
  pwm.setPWMFreq(330);  // Digital servos run at ~330 Hz updates

  // pin setting for Black Pill for test LEDs
//  pinMode(PB9, OUTPUT);
//  pinMode(PB8, OUTPUT);

  // tft setting
  tft.init();
  tft.setRotation(0);

  // tft start setting
  tft_start_setting();
  text_setting();
  main_menu_page();
}

void loop() {
  tft_task_manager();
}

This is the c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "arduino",
            "includePath": [
                "${workspaceFolder}/**",
                "E:/Programs_Files/Arduino/hardware",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/variants/esp32",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/cores/esp32",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/libraries/SPI/src",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/dio_qspi/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/qio_qspi/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/dout_qspi/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/qout_qspi/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/libraries/Wire/src",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/freertos/include/freertos",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/freertos/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/freertos/include/esp_additions/freertos",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/esp_common/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/freertos/port/xtensa/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/xtensa/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/xtensa/esp32/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/esp_rom/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/esp_rom/include/linux",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/esp_hw_support/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/hal/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/soc/esp32/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/hal/esp32/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/soc/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/esp_system/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/esp_timer/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/newlib/platform_include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/heap/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/log/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/driver/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/spi_flash/include",
                "E:/Programs_Files/Arduino/hardware/arduino-esp32-master/tools/sdk/esp32/include/esp_hw_support/include/soc",
                "E:/Programs_Files/Arduino/libraries",
                "E:/Programs_Files/Arduino/libraries/TFT_eSPI",
                "E:/Programs_Files/Arduino/libraries/PNGdec-master/src",
                "E:/Programs_Files/Arduino/libraries/Adafruit-PWM-Servo-Driver-Library-master",
                "E:/Programs_Files/Arduino/libraries/stepper_dev_prj/src",
                "E:/Programs_Files/Arduino/libraries/my_keywords"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:/Users/eagle/AppData/Local/Arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/xtensa-esp32-elf-gcc"
        }
    ],
    "version": 4
}

What could be the problem ?

Interesting..

not using this but quick look into it..
looks like it's using Arduino Cli and because of this I would have expected the libraries would be held in the same place..
documents\arduino\libraries
obviously it's not finding the TFT_eSPI..
I see mention of a library manager inside of vscode, did you look in there??
does it show this lib as installed??

sorry for your troubles..

good luck.. ~q

1 Like

Yes, but you can point to the compiler which is the VS code manager where the libraries are. And that's done in c_cpp_properties.json

obviously it's not finding the TFT_eSPI..

In Arduino IDE, the default libraries location is "documents\arduino\libraries", but also there's another libraries folder inside Arduino IDE installation directory.

I see mention of a library manager inside of vscode, did you look in there??
Yeah, it's the same as the one in Arduino IDE which is to install libraries through the IDE to the default libraries location in documents\arduino\libraries and not in the one inside the installation directory. All that is manageable either with Arduino IDE or VS code.

sorry for your troubles..
Yep, I will try to get it to work. eventually :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.