Skip to content

Compilation error when using PlatformIO and Ethernet.h #10760

Closed
@MicSG-dev

Description

@MicSG-dev

Board

ESP Dev Module

Device Description

Module on breadboard.

Hardware Configuration

Software problem.
There is no hardware as the problem is in the software.

Version

v3.1.0

IDE Name

VSCode PlatformIO

Operating System

Windows 11 Pro 23H2 - Compilation 22631.4037

Flash frequency

80MHz

PSRAM enabled

no

Upload speed

921600

Description

When using PlatformIO with the following platformio.ini file:

[env:esp32dev]
platform = espressif32@ 6.9.0
board = esp32dev
framework = arduino
lib_deps =
    arduino-libraries/Ethernet@^2.0.2

And running the WebServer example, several compilation errors occur.

Sketch

/*
 Web Server

 A simple web server that shows the value of the analog input pins.
 using an Arduino WIZnet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 modified 02 Sept 2015
 by Arturo Guadalupi
 
 */

#include <Arduino.h>
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
  // You can use Ethernet.init(pin) to configure the CS pin
  //Ethernet.init(10);  // Most Arduino shields
  Ethernet.init(5);   // MKR ETH Shield
  //Ethernet.init(0);   // Teensy 2.0
  //Ethernet.init(20);  // Teensy++ 2.0
  //Ethernet.init(15);  // ESP8266 with Adafruit FeatherWing Ethernet
  //Ethernet.init(33);  // ESP32 with Adafruit FeatherWing Ethernet

  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Ethernet WebServer Example");

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }

  // start the server
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an HTTP request ends with a blank line
    bool currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the HTTP request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard HTTP response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

Debug Message

src/main.cpp: In function 'void loop()':
src/main.cpp:75:43: error: cannot allocate an object of abstract type 'EthernetClient'
   75 |   EthernetClient client = server.available();
      |                           ~~~~~~~~~~~~~~~~^~
In file included from src/main.cpp:22:
.pio/libdeps/esp32dev/Ethernet/src/Ethernet.h:214:7: note:   because the following virtual functions are pure within 'EthernetClient':
  214 | class EthernetClient : public Client {
      |       ^~~~~~~~~~~~~~
In file included from C:/Users/MichelGalvao/.platformio/packages/framework-arduinoespressif32@src-e5a7fd5d9117bd8a322277fde59ac3d3/cores/esp32/Arduino.h:197,
                 from src/main.cpp:20:
C:/Users/MichelGalvao/.platformio/packages/framework-arduinoespressif32@src-e5a7fd5d9117bd8a322277fde59ac3d3/cores/esp32/Client.h:29:15: note:     'virtual int Client::connect(IPAddress, uint16_t, int32_t)'
   29 |   virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) = 0;
      |               ^~~~~~~
C:/Users/MichelGalvao/.platformio/packages/framework-arduinoespressif32@src-e5a7fd5d9117bd8a322277fde59ac3d3/cores/esp32/Client.h:31:15: note:     'virtual int Client::connect(const char*, uint16_t, int32_t)'
   31 |   virtual int connect(const char *host, uint16_t port, int32_t timeout) = 0;
      |               ^~~~~~~
src/main.cpp:75:18: error: cannot declare variable 'client' to be of abstract type 'EthernetClient'
   75 |   EthernetClient client = server.available();
      |                  ^~~~~~
Compiling .pio\build\esp32dev\FrameworkArduino\FunctionalInterrupt.cpp.o
*** [.pio\build\esp32dev\src\main.cpp.o] Error 1
.pio/libdeps/esp32dev/Ethernet/src/EthernetServer.cpp:40:16: error: invalid abstract return type for member function 'EthernetClient EthernetServer::available()'
   40 | EthernetClient EthernetServer::available()
      |                ^~~~~~~~~~~~~~
In file included from .pio/libdeps/esp32dev/Ethernet/src/EthernetServer.cpp:22:
.pio/libdeps/esp32dev/Ethernet/src/Ethernet.h:214:7: note:   because the following virtual functions are pure within 'EthernetClient':
  214 | class EthernetClient : public Client {
      |       ^~~~~~~~~~~~~~
In file included from C:/Users/MichelGalvao/.platformio/packages/framework-arduinoespressif32@src-e5a7fd5d9117bd8a322277fde59ac3d3/cores/esp32/Arduino.h:197,
                 from .pio/libdeps/esp32dev/Ethernet/src/EthernetServer.cpp:21:
C:/Users/MichelGalvao/.platformio/packages/framework-arduinoespressif32@src-e5a7fd5d9117bd8a322277fde59ac3d3/cores/esp32/Client.h:29:15: note:     'virtual int Client::connect(IPAddress, uint16_t, int32_t)'
   29 |   virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) = 0;
      |               ^~~~~~~
C:/Users/MichelGalvao/.platformio/packages/framework-arduinoespressif32@src-e5a7fd5d9117bd8a322277fde59ac3d3/cores/esp32/Client.h:31:15: note:     'virtual int Client::connect(const char*, uint16_t, int32_t)'
   31 |   virtual int connect(const char *host, uint16_t port, int32_t timeout) = 0;
      |               ^~~~~~~
.pio/libdeps/esp32dev/Ethernet/src/EthernetServer.cpp: In member function 'EthernetClient EthernetServer::available()':
.pio/libdeps/esp32dev/Ethernet/src/EthernetServer.cpp:47:54: error: invalid cast to abstract class type 'EthernetClient'
   47 |         if (!chip) return EthernetClient(MAX_SOCK_NUM);
      |                                                      ^
.pio/libdeps/esp32dev/Ethernet/src/EthernetServer.cpp:72:40: error: invalid cast to abstract class type 'EthernetClient'
   72 |         return EthernetClient(sockindex);
      |                                        ^
.pio/libdeps/esp32dev/Ethernet/src/EthernetServer.cpp: At global scope:
.pio/libdeps/esp32dev/Ethernet/src/EthernetServer.cpp:75:16: error: invalid abstract return type for member function 'EthernetClient EthernetServer::accept()'
   75 | EthernetClient EthernetServer::accept()
      |                ^~~~~~~~~~~~~~
.pio/libdeps/esp32dev/Ethernet/src/EthernetServer.cpp: In member function 'EthernetClient EthernetServer::accept()':
.pio/libdeps/esp32dev/Ethernet/src/EthernetServer.cpp:82:54: error: invalid cast to abstract class type 'EthernetClient'
   82 |         if (!chip) return EthernetClient(MAX_SOCK_NUM);
      |                                                      ^
.pio/libdeps/esp32dev/Ethernet/src/EthernetServer.cpp:104:40: error: invalid cast to abstract class type 'EthernetClient'
  104 |         return EthernetClient(sockindex);
      |                                        ^
.pio/libdeps/esp32dev/Ethernet/src/EthernetServer.cpp: In member function 'virtual size_t EthernetServer::write(const uint8_t*, size_t)':
.pio/libdeps/esp32dev/Ethernet/src/EthernetServer.cpp:170:18: error: cannot allocate an object of abstract type 'EthernetClient'
  170 |         available();
      |         ~~~~~~~~~^~
*** [.pio\build\esp32dev\libe72\Ethernet\EthernetServer.cpp.o] Error 1

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Activity

lbernstone

lbernstone commented on Dec 20, 2024

@lbernstone
Contributor

You are using a library designed for Arduino/AVR. Use the native esp32 library

JAndrassy

JAndrassy commented on Dec 20, 2024

@JAndrassy
Contributor

@lbernstone this is the TinyGSM library's HttpClient example compilation error. what is your advice for that?

..\HttpClient.ino:134:15: error: cannot declare variable 'client' to be of abstract type 'TinyGsmSim800::GsmClientSim800'
  134 | TinyGsmClient client(modem);
      |               ^~~~~~
In file included from C:\lab\Sloeber\arduinoPlugin\libraries\TinyGSM\0.12.0\src/TinyGsmClient.h:13,
                 from ..\sloeber.ino.cpp:26:
C:\lab\Sloeber\arduinoPlugin\libraries\TinyGSM\0.12.0\src/TinyGsmClientSIM800.h:86:9: note:   because the following virtual functions are pure within 'TinyGsmSim800::GsmClientSim800':
   86 |   class GsmClientSim800 : public GsmClient {
      |         ^~~~~~~~~~~~~~~
In file included from C:\lab\Sloeber\arduinoPlugin\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Arduino.h:197,
                 from ..\sloeber.ino.cpp:7:
C:\lab\Sloeber\arduinoPlugin\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Client.h:29:15: note:     'virtual int Client::connect(IPAddress, uint16_t, int32_t)'
   29 |   virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) = 0;
      |               ^~~~~~~
C:\lab\Sloeber\arduinoPlugin\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Client.h:31:15: note:     'virtual int Client::connect(const char*, uint16_t, int32_t)'
   31 |   virtual int connect(const char *host, uint16_t port, int32_t timeout) = 0;
      |               ^~~~~~~
..\HttpClient.ino:135:15: error: cannot declare variable 'http' to be of abstract type 'HttpClient'
  135 | HttpClient    http(client, server, port);
      |               ^~~~
In file included from C:\Users\andrassy\Documents\Arduino\libraries\ArduinoHttpClient\src/ArduinoHttpClient.h:8,
                 from ..\sloeber.ino.cpp:27:
C:\Users\andrassy\Documents\Arduino\libraries\ArduinoHttpClient\src/HttpClient.h:41:7: note:   because the following virtual functions are pure within 'HttpClient':
   41 | class HttpClient : public Client
      |       ^~~~~~~~~~
C:\lab\Sloeber\arduinoPlugin\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Client.h:29:15: note:     'virtual int Client::connect(IPAddress, uint16_t, int32_t)'
   29 |   virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) = 0;
      |               ^~~~~~~
C:\lab\Sloeber\arduinoPlugin\packages\esp32\hardware\esp32\3.1.0\cores\esp32/Client.h:31:15: note:     'virtual int Client::connect(const char*, uint16_t, int32_t)'
   31 |   virtual int connect(const char *host, uint16_t port, int32_t timeout) = 0;
      |               ^~~~~~~
Jason2866

Jason2866 commented on Dec 20, 2024

@Jason2866
Collaborator

@JAndrassy The TinyGSM library needs to be adopted. Native SIM PPP support is integrated in espressif32 Arduino core.

me-no-dev

me-no-dev commented on Dec 20, 2024

@me-no-dev
Member

libs need to be updated for 3.1

me-no-dev

me-no-dev commented on Dec 20, 2024

@me-no-dev
Member

but as @Jason2866 said. we now have native ppp support

JAndrassy

JAndrassy commented on Dec 20, 2024

@JAndrassy
Contributor

so now the esp32 Arduino team defines the Arduino API and all libraries should reflect the changes?

me-no-dev

me-no-dev commented on Dec 20, 2024

@me-no-dev
Member

we define additions as required. New gcc versions that come with IDF drive some of those changes. We also provide a way to detect the version and extend the classes only when necessary. We have extended many Arduino classes so far. Libs do not need to update, but they will be incompatible with newer versions of our core. Using old version is always an option

Jason2866

Jason2866 commented on Dec 20, 2024

@Jason2866
Collaborator

Not enhancing the API would mean not fully supporting the new available features from new MCUs (like the C6 and P4). Not doing this would mean, people using Arduino couldn't use this new great features of this chips. Not the way development works. So yes espressif is doing enhancements when needed. Arduino enhancement is not a one way train.

MicSG-dev

MicSG-dev commented on Dec 20, 2024

@MicSG-dev
Author

You are using a library designed for Arduino/AVR. Use the native esp32 library

This statement that the arduino-libraries/Ethernet library is not compatible with ESP32 is very WRONG.

Below is the proof that the arduino-libraries/Ethernet library IS compatible with ESP32:

  1. On the PlatformIO Registration page it clearly says that the arduino-libraries/Ethernet library is compatible with ANY PLATFORM.
    image
    Source: https://registry.platformio.org/libraries/arduino-libraries/Ethernet/compatibility

  2. When searching for ESP32 in the library repository, there are several results, clearly indicating that the use of the library with ESP32 is COMPATIBLE.
    image
    Source: https://github.com/search?q=repo%3Aarduino-libraries%2FEthernet%20esp32&type=code

  3. In the examples of the arduino-libraries/Ethernet library, there is a clear indication of use of ESP32 (including platforms other than AVR), clearly indicating that the use of the library with ESP32 is COMPATIBLE.
    image
    Source: https://github.com/arduino-libraries/Ethernet/blob/b16c38a5bd0e25143da8d0e9cdeba5b90db62d0a/examples/WebServer/WebServer.ino#L42

  4. In the properties file of the arduino-libraries/Ethernet library (library.properties) it clearly says that it is COMPATIBLE with any architecture.
    image
    Source: https://github.com/arduino-libraries/Ethernet/blob/b16c38a5bd0e25143da8d0e9cdeba5b90db62d0a/library.properties#L9

  5. I successfully compiled and uploaded the WebServer example of the arduino-libraries/Ethernet library to an ESP32!! (using an Arduino IDE).
    image

With all this irrefutable evidence, I hope you (@lbernstone and @Jason2866 [reply]) stop claiming that the arduino-libraries/Ethernet library is not compatible with the ESP32, when in fact it IS COMPATIBLE with the ESP32.

And about the ETH.h library, I already used this library a few days ago with ESP32 and W5500 and there were always random disconnections (triggering the ARDUINO_EVENT_ETH_DISCONNECTED event). With the trusted Ethernet.h library there are no such disconnections. That's why I would prefer to use Ethernet.h. but still, thanks for the suggestion.

MicSG-dev

MicSG-dev commented on Dec 20, 2024

@MicSG-dev
Author

I don't know what happened with the Client.h file (from the esp32 core), but according to @per1234 (arduino-libraries/Ethernet#277 (comment)) there seems to have been some mishap that causes the problem I'm facing.

14 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Compilation error when using PlatformIO and Ethernet.h · Issue #10760 · espressif/arduino-esp32