Errors when compiling ESP32 code

Hello All, I’m about at my wits end. yesterday all my code compiled fine. Now this morning I haven’t been able to get anything to compile. The only think I can think of that I did between last night and tonight is I started a new project now neither it or anything else using these same libraries and boards will compile.

I have gone as far as uninstalling both VSCode and PlatformIO and reinstalling also creating all new projects from scratch and only copying my main.cpp code in and letting pIO generate new files and (I assume) loading in the lib dependencies anew.

I’m not sure what exactly you need to help me trace the issue so I’ll start with the build errors.

Processing esp-wrover-kit (platform: espressif32; board: esp-wrover-kit; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp-wrover-kit.html
PLATFORM: Espressif 32 1.11.1 > Espressif ESP-WROVER-KIT
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (ftdi) On-board (ftdi) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: toolchain-xtensa32 2.50200.80 (5.2.0), framework-arduinoespressif32 2.10004.191002 (1.0.4), tool-esptoolpy 1.20600.0 (2.6.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 35 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <WiFi> 1.2.7
|   |-- <SPI> 1.0
|-- <HTTPClient> 1.2
|   |-- <WiFi> 1.2.7
|   |   |-- <SPI> 1.0
|   |-- <WiFiClientSecure> 1.0
|   |   |-- <WiFi> 1.2.7
|   |   |   |-- <SPI> 1.0
|-- <ESP Async WebServer> 1.2.3 #f13685e
|   |-- <AsyncTCP> 1.1.1 #ca8ac5f
|   |-- <WiFi> 1.2.7
|   |   |-- <SPI> 1.0
|-- <AsyncTCP> 1.1.1 #ca8ac5f
|-- <EEPROM> 1.0.3
Building in release mode
Compiling .pio\build\esp-wrover-kit\libc71\WiFiClientSecure\WiFiClientSecure.cpp.o
Compiling .pio\build\esp-wrover-kit\libc71\WiFiClientSecure\ssl_client.cpp.o
Compiling .pio\build\esp-wrover-kit\lib4e1\HTTPClient\HTTPClient.cpp.o
Archiving .pio\build\esp-wrover-kit\lib745\libAsyncTCP.a
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp: In constructor 'WiFiClientSecure::WiFiClientSecure()':
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp:33:5: error: '_connected' was not declared in
this scope
     _connected = false;
     ^
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp: In constructor 'WiFiClientSecure::WiFiClientSecure(int)':
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp:50:5: error: '_connected' was not declared in
this scope
     _connected = false;
     ^
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp: In member function 'WiFiClientSecure& WiFiClientSecure::operator=(const WiFiClientSecure&)':
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp:80:5: error: '_connected' was not declared in
this scope
     _connected = other._connected;
     ^
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp:80:24: error: 'const class WiFiClientSecure' has no member named '_connected'
     _connected = other._connected;
                        ^
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp: In member function 'virtual void WiFiClientSecure::stop()':
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp:89:9: error: '_connected' was not declared in
this scope
         _connected = false;
         ^
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp: In member function 'int WiFiClientSecure::connect(const char*, uint16_t, const char*, const char*, const char*)':
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp:136:5: error: '_connected' was not declared in this scope
     _connected = true;
     ^
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp: In member function 'int WiFiClientSecure::connect(const char*, uint16_t, const char*, const char*)':
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp:156:5: error: '_connected' was not declared in this scope
     _connected = true;
     ^
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp: In member function 'virtual size_t WiFiClientSecure::write(const uint8_t*, size_t)':
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp:185:10: error: '_connected' was not declared in this scope
     if (!_connected) {
          ^
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp: In member function 'virtual int WiFiClientSecure::available()':
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp:229:10: error: '_connected' was not declared in this scope
     if (!_connected) {
          ^
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp: In member function 'virtual uint8_t WiFiClientSecure::connected()':
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\WiFiClientSecure.cpp:245:12: error: '_connected' was not declared in this scope
     return _connected;
            ^
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\ssl_client.cpp: In function 'int start_ssl_client(sslclient_context*, const char*, uint32_t, int, const char*, const char*, const char*, const char*, const char*)':
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure\src\ssl_client.cpp:68:9: error: 'WiFiGenericClass' has not been declared
     if(!WiFiGenericClass::hostByName(host, srv)){
         ^
Compiling .pio\build\esp-wrover-kit\lib5f1\ESP Async WebServer\AsyncEventSource.cpp.o
Compiling .pio\build\esp-wrover-kit\lib5f1\ESP Async WebServer\AsyncWebSocket.cpp.o
Compiling .pio\build\esp-wrover-kit\lib5f1\ESP Async WebServer\SPIFFSEditor.cpp.o
Compiling .pio\build\esp-wrover-kit\lib5f1\ESP Async WebServer\WebAuthentication.cpp.o
*** [.pio\build\esp-wrover-kit\libc71\WiFiClientSecure\WiFiClientSecure.cpp.o] Error 1
*** [.pio\build\esp-wrover-kit\libc71\WiFiClientSecure\ssl_client.cpp.o] Error 1
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\HTTPClient\src\HTTPClient.cpp: In member function 'bool HTTPClient::connect()':
C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\HTTPClient\src\HTTPClient.cpp:1017:63: error: no matching function for call to 'WiFiClient::connect(const char*, uint16_t&, int32_t&)'
     if(!_client->connect(_host.c_str(), _port, _connectTimeout)) {
                                                               ^
In file included from C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\HTTPClient\src\HTTPClient.h:34:0,
                 from C:\users\atcla\.platformio\packages\framework-arduinoespressif32\libraries\HTTPClient\src\HTTPClient.cpp:40:
.pio\libdeps\esp-wrover-kit\WiFi_ID870\src/WiFiClient.h:34:15: note: candidate: virtual int WiFiClient::connect(IPAddress, uint16_t)
   virtual int connect(IPAddress ip, uint16_t port);
               ^
.pio\libdeps\esp-wrover-kit\WiFi_ID870\src/WiFiClient.h:34:15: note:   candidate expects 2 arguments, 3 provided
.pio\libdeps\esp-wrover-kit\WiFi_ID870\src/WiFiClient.h:35:15: note: candidate: virtual int WiFiClient::connect(const char*, uint16_t)
   virtual int connect(const char *host, uint16_t port);
               ^
.pio\libdeps\esp-wrover-kit\WiFi_ID870\src/WiFiClient.h:35:15: note:   candidate expects 2 arguments, 3 provided
*** [.pio\build\esp-wrover-kit\lib4e1\HTTPClient\HTTPClient.cpp.o] Error 1
In file included from .pio\libdeps\esp-wrover-kit\ESP Async WebServer\src\SPIFFSEditor.h:3:0,
                 from .pio\libdeps\esp-wrover-kit\ESP Async WebServer\src\SPIFFSEditor.cpp:1:
.pio\libdeps\esp-wrover-kit\ESP Async WebServer\src/ESPAsyncWebServer.h:27:16: fatal error: FS.h: No such file or directory

************************************************************
* Looking for FS.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:FS.h"
* Web  > https://platformio.org/lib/search?query=header:FS.h
*
************************************************************

compilation terminated.
In file included from .pio\libdeps\esp-wrover-kit\ESP Async WebServer\src\AsyncEventSource.h:31:0,
                 from .pio\libdeps\esp-wrover-kit\ESP Async WebServer\src\AsyncEventSource.cpp:21:
.pio\libdeps\esp-wrover-kit\ESP Async WebServer\src/ESPAsyncWebServer.h:27:16: fatal error: FS.h: No such file or directory

************************************************************
* Looking for FS.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:FS.h"
* Web  > https://platformio.org/lib/search?query=header:FS.h
*
************************************************************

In file included from .pio\libdeps\esp-wrover-kit\ESP Async WebServer\src\AsyncWebSocket.h:32:0,
                 from .pio\libdeps\esp-wrover-kit\ESP Async WebServer\src\AsyncWebSocket.cpp:22:
.pio\libdeps\esp-wrover-kit\ESP Async WebServer\src/ESPAsyncWebServer.h:27:16: fatal error: FS.h: No such file or directory

************************************************************
* Looking for FS.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:FS.h"
* Web  > https://platformio.org/lib/search?query=header:FS.h
*
************************************************************

compilation terminated.
compilation terminated.
*** [.pio\build\esp-wrover-kit\lib5f1\ESP Async WebServer\SPIFFSEditor.cpp.o] Error 1
*** [.pio\build\esp-wrover-kit\lib5f1\ESP Async WebServer\AsyncWebSocket.cpp.o] Error 1
*** [.pio\build\esp-wrover-kit\lib5f1\ESP Async WebServer\AsyncEventSource.cpp.o] Error 1
=================================================================== [FAILED] Took 4.29 seconds ===================================================================
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

And my main.cpp


#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <EEPROM.h>           // include library to read and write from flash memory

#define EEPROM_SIZE 4         // define the number of bytes you want to access in flash memory
#define modeButton 13         // define the pin the mode changing button is on
 
char ssid[]     = "SampleNetwork";
const char* password  = "987654321";
int timeout_counter = 0;
//float numToDisplay = 0.00;
String mac;
int remoteMode = 0;
bool isModeChange = false;
int maxMode = 4;
unsigned long lastModeTime = 0;
unsigned long modeTimeDelay = 1500;
unsigned long firstbootTimeDelay = 6000;
bool firstboot = true;

String fallbackWeight;


void modeInt() {
    isModeChange = true;
}


void setup() {
 
  Serial.begin(115200);
  Serial.println("Opening Serial Monitor..");
  delay(100);
  Serial2.begin(9600, SERIAL_8N1,19,21);
  Serial.println("Opening Serial2 to Display..");
  delay(100);
    // initialize EEPROM with predefined size
  EEPROM.begin(EEPROM_SIZE);

  pinMode(modeButton, INPUT_PULLUP);

    // read the last LED state from flash memory
  remoteMode = EEPROM.read(0);

  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    Serial2.println("Er02");  // Error 02 Unable to connect to wifi
    Serial.println("Connecting to WiFi..");
  }
 
  Serial.println("Connected to the WiFi network");
 // mac = WiFi.macAddress();
   Serial.println(mac);
 
  attachInterrupt(digitalPinToInterrupt(modeButton),modeInt, FALLING);
  
  lastModeTime = millis();
}
 
void loop() {
  String payloadWeight;

  if ((millis() - lastModeTime) < modeTimeDelay) {
    String mode = " F" + String(remoteMode) + " ";
    Serial2.println(mode);
  } else {
    firstboot = false;
    if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
  
      HTTPClient http;

      http.begin("http://192.168.1.184/remote"); //Specify the URL
      int httpCode = http.POST(String(remoteMode));                                        //Make the request
  
      if (httpCode > 0) { //Check for the returning code 
        payloadWeight = http.getString();
        fallbackWeight = payloadWeight;
      } else {
        payloadWeight = fallbackWeight;
        Serial.println("Error on HTTP request");
        //Serial2.println("Er04");  // Error 04 on HTTP remote request
      } 
      http.end(); //Free the resources
    }else {
      Serial2.println("Er02");  // Error 02 Unable to connect to wifi
      timeout_counter++;
    }

      Serial.println(payloadWeight);
      // If a colon is found in string then we know it's lb/oz
      // if (payloadWeight.indexOf(":") != -1){
      //   Serial2.println(payloadWeight.substring(0, payloadWeight.indexOf(".")));
      // } else {
      //   Serial2.println(payloadWeight.substring(0, 5));

      // }
      Serial2.println(payloadWeight.substring(0, 5));
      //delay(30);
  }
  

 
  if (timeout_counter > 20) {
        Serial.println("Restarting: Attempting to reestablish wi-fi connecton");
        delay(1000);
        ESP.restart();
  }



  
  if(isModeChange) {
     String payloadMaxMode = "";

      if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
    
        HTTPClient http;

        http.begin("http://192.168.1.184/getmaxmode"); //Specify the URL
        int httpCode = http.GET();                                        //Make the request
    
        if (httpCode > 0) { //Check for the returning code 
          payloadMaxMode = http.getString();
          maxMode = std::atoi(payloadMaxMode.c_str());
        } else {
          Serial.println("Error on HTTP request");
          Serial2.println("Er03");  // Error on Max Mode HTTP Request
        } 
        http.end(); //Free the resources
      }else {
        Serial2.println("Er02");  // Error 02 Unable to connect to wifi
      }

    if(remoteMode >= maxMode) {
      remoteMode = 1;
    } else {
      remoteMode++;
    }
    Serial.print("Mode Button Pressed: ");
    Serial.println(remoteMode);
    isModeChange = false;
    lastModeTime = millis();
    EEPROM.write(0, remoteMode);
    EEPROM.commit();
    Serial.println("Remote Mode saved in flash memory");
  }
  
}

Finally my platformio.ini:

    ;PlatformIO Project Configuration File
    ;
    ;   Build options: build flags, source filter
    ;   Upload options: custom upload port, speed and extra flags
    ;   Library options: dependencies, extra library storages
    ;   Advanced options: extra scripting
    ;
    ; Please visit documentation for the other options and examples
    ; https://docs.platformio.org/page/projectconf.html

    [env:esp-wrover-kit]
    platform = espressif32
    board = esp-wrover-kit
    framework = arduino

    lib_deps =
        WiFi
        HTTPClient
        eeprom
        ESP Async WebServer
        AsyncTCP

These libraries are not used though? I tested the main.cpp with no lib_deps statement and it compiled.

Also all the needed libraries are internal to the Arduino framework and don’t need to be declared via lib_deps.

Dependency Graph
|-- <EEPROM> 1.0.3 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\EEPROM)
|-- <WiFi> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|-- <HTTPClient> 1.2 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\HTTPClient)
|   |-- <WiFi> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)
|   |-- <WiFiClientSecure> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\WiFiClientSecure)
|   |   |-- <WiFi> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinoespressif32\libraries\WiFi)

Since you declared them it uses some funky libraries as you see in your dependency graph above (refer mine)

So as a first thing I’d suggest removing all lib_deps statement and removing the .pio folder of the project (to remove previously downloaded libraries).

Thank you so much!

That did it!

How is it you knew that the WiFi, HTTPClient and eeprom libraries were internal to the Arduino framework? Is there some part of the documentation that I am not reading correctly? or maybe looking at the wrong documentation?

Thanks again for helping me out! I’ve been fighting this all day.

Well Arduino-ESP32 is in the repository GitHub - espressif/arduino-esp32: Arduino core for the ESP32 and the libraries folder contains all built-in libraries. There’s WiFi, HTTPClient, EEPROM etc. So I would first look there if it’s something basic like a HTTP client, which you expect to be part of the base framework libraries.

Another good way to avoid problems is, like I did, use Verbose Build task (or pio run -v), which prints the path to used libraries. If something weird comes up (e.g. a supposedly internal library is suddenly sourced from the libdeps folder for externally downloaded libraries), you’ll see it.

Great! that makes sense! Again I appreciate your time and help!

How did you make the “Dependency Graph”? I find docs for LDF but not this DG.
Thanks

It’s automatically outputted as one of the first things at the start of the compilation process. If you do a verbose compile (-v), it will additionally show the paths. There are no other settings (other than the LDF setting which influences where / how it searches).

1 Like

Can the terminal window be logged or piped to a file?

Sorry noob to pio (:sunglasses:

You can open a PIO terminal (Redirecting...) and type pio run -v there and press Ctrl+C to abort, or pio run -v > build_log.txt 2>&1 for pipe redirection.

1 Like