#error: invalid abstract return type 'WiFiClient' PlatformIO / Arduino

87 messages · Page 1 of 1 (latest)

frozen summit
#

i'm trying to build a simple wifi connector for ESP32 Using PlatformIO over Arduino Framework,

but for some reasons it does that

In file included from C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFi.h:38,
                 from src/Wifi/WifiHandler.h:4,
                 from src/main.cpp:4:
C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiServer.h:48:5: error: invalid abstract return type 'WiFiClient'
     WiFiClient available();
     ^~~~~~~~~~
In file included from C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFi.h:37,
                 from src/Wifi/WifiHandler.h:4,
                 from src/main.cpp:4:
C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiClient.h:39:7: note:   because the following virtual functions are pure within 'WiFiClient':
 class WiFiClient : public ESPLwIPClient
       ^~~~~~~~~~
In file included from C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/cores/esp32/arduino.h:193,
                 from .pio/libdeps/esp-wrover-kit/Freenove VK16K33 Lib/src/Freenove_VK16K33_Lib.h:6,
                 from lib/Freenove/src/Car_Emotion.h:4,
                 from src/main.cpp:1:
C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/cores/esp32/Client.h:29:17: note:      'virtual int Client::connect(IPAddress, uint16_t)'
     virtual int connect(IPAddress ip, uint16_t port) =0;
                 ^~~~~~~
C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/cores/esp32/Client.h:30:17: note:      'virtual int Client::connect(const char*, uint16_t)'
     virtual int connect(const char *host, uint16_t port) =0;
                 ^~~~~~~
In file included from C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFi.h:38,
                 from src/Wifi/WifiHandler.h:4,
                 from src/main.cpp:4:
C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiServer.h:49:5: error: invalid abstract return type 'WiFiClient'
     WiFiClient accept(){return available();}
     ^~~~~~~~~~Compiling .pio\build\esp-wrover-kit\lib088\Adafruit GFX Library\Adafruit_GFX.cpp.o

C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiServer.h:49:16: error: invalid abstract return type for member function 'WiFiClient WiFiServer::accept()' 
     WiFiClient accept(){return available();}
                ^~~~~~
C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiServer.h: In member function 'WiFiClient WiFiServer::accept()':
C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src/WiFiServer.h:49:42: error: cannot allocate an object of abstract type 'WiFiClient'
     WiFiClient accept(){return available();}
                                          ^
Compiling .pio\build\esp-wrover-kit\lib088\Adafruit GFX Library\Adafruit_GrayOLED.cpp.o
Compiling .pio\build\esp-wrover-kit\lib088\Adafruit GFX Library\Adafruit_SPITFT.cpp.o
*** [.pio\build\esp-wrover-kit\src\main.cpp.o] Error 1

Dependency Graph
|-- Freenove VK16K33 Lib @ 1.0.0
|-- Freenove WS2812 Lib for ESP32 @ 1.0.6
|-- PubSubClient @ 2.8.0
|-- IRremote @ 4.3.2
|-- Adafruit SSD1306 @ 2.5.10
|-- Adafruit GFX Library @ 1.11.9
|-- Adafruit BusIO @ 1.16.1
|-- BasicIOStream @ 1.0.1
|-- LiquidCrystal @ 1.5.0
|-- SPI @ 2.0.0
|-- Wire @ 2.0.0
|-- Freenove 4WD modules @ 1.0.5
|-- WiFi @ 2.0.0

nimble sirenBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

frozen summit
#

i don't quite understand it as i can't seem to see it anywhere on google, as all the other people i saw having that issue is basically having an ESP8266, and have a collision betwenn Wifi and ESP8266Wifi

i don't have that collision and can't seem to find the error, i just started Cpp

cunning gulch
#

Because i am not that much knowledgeable with these difficulty level

frozen summit
#

chatgpt tends to be quite stupid with those, and he is, just aked "make sure it's all up to date"

yeah it is, i just installed all of it yesterday

minor bane
nimble sirenBOT
#
Large Language Models (LLMs)

We highly recommend against the use of LLMs and AI assistants because:

  • LLMs are bad at C and C++
  • LLMs are wrong more often than not
  • LLMs answer with complete confidence even when wrong
  • If you're new to C or C++ you likely don't know enough to know when answers are wrong
frozen summit
#
/*
  Server.h - Server class for Raspberry Pi
  Copyright (c) 2016 Hristo Gochkov  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
#ifndef _WIFISERVER_H_
#define _WIFISERVER_H_

#include "Arduino.h"
#include "Server.h"
#include "WiFiClient.h"

class WiFiServer : public Server {
  private:
    int sockfd;
    int _accepted_sockfd = -1;
    uint16_t _port;
    uint8_t _max_clients;
    bool _listening;
    bool _noDelay = false;

  public:
    void listenOnLocalhost(){}

    WiFiServer(uint16_t port=80, uint8_t max_clients=4):sockfd(-1),_accepted_sockfd(-1),_port(port),_max_clients(max_clients),_listening(false),_noDelay(false){}
    ~WiFiServer(){ end();}
    WiFiClient available();
    WiFiClient accept(){return available();}
    void begin(uint16_t port=0);
    void begin(uint16_t port, int reuse_enable);
    void setNoDelay(bool nodelay);
    bool getNoDelay();
    bool hasClient();
    size_t write(const uint8_t *data, size_t len);
    size_t write(uint8_t data){
      return write(&data, 1);
    }
    using Print::write;

    void end();
    void close();
    void stop();
    operator bool(){return _listening;}
    int setTimeout(uint32_t seconds);
    void stopAll();
};

#endif /* _WIFISERVER_H_ */

#

mine looks like that

#

wait, i saw the header comment

#

rasperry pi ? uhh

#

thonk something is wrong there

#

i'm on clean install tho

minor bane
#

WiFiClient could/should have been forward declared too.
But don't go changing that.

frozen summit
#

i'm not sure what to do, manually add the arduino-esp32 into my packages and try to use it from the platformio.ini ?

minor bane
#

I don't know where you got yours from.

frozen summit
#

from the paltformio VSCode extension

#
platform = espressif32
board = esp32dev
framework = arduino

in the platformio.ini it determine the package to use using this

minor bane
#

I'm afraid I cannot help you in that decision.

frozen summit
#

heh, thank you anyway, gonna try to mess around, but i have a clear view of what's wrong now, thank you

nimble sirenBOT
#

@frozen summit Has your question been resolved? If so, type !solved :)

frozen summit
#

welp

frozen summit
#

it says these methods aren't implemented

#

when those are ?

minor bane
#

Thing is, there is no actual class WiFiClient in the GH version.
It's just an alias of class NetworkClient.

I'd need to see your version of "WiFiClient.h".

frozen summit
#
/*
  Client.h - Base class that provides Client
  Copyright (c) 2011 Adrian McEwen.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef _WIFICLIENT_H_
#define _WIFICLIENT_H_


#include "Arduino.h"
#include "Client.h"
#include <memory>

class WiFiClientSocketHandle;
class WiFiClientRxBuffer;

class ESPLwIPClient : public Client
{
public:
        virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) = 0;
        virtual int connect(const char *host, uint16_t port, int32_t timeout) = 0;
        virtual int setTimeout(uint32_t seconds) = 0;
};

class WiFiClient : public ESPLwIPClient
{
protected:
    std::shared_ptr<WiFiClientSocketHandle> clientSocketHandle;
    std::shared_ptr<WiFiClientRxBuffer> _rxBuffer;
    bool _connected;
    int _timeout;

public:
    WiFiClient *next;
    WiFiClient();
    WiFiClient(int fd);
    ~WiFiClient();
    int connect(IPAddress ip, uint16_t port);
    int connect(IPAddress ip, uint16_t port, int32_t timeout_ms);
    int connect(const char *host, uint16_t port);
    int connect(const char *host, uint16_t port, int32_t timeout_ms);
    size_t write(uint8_t data) override;
    size_t write(const uint8_t *buf, size_t size);
    size_t write_P(PGM_P buf, size_t size);
    size_t write(Stream &stream);
    int available();
    int read();
    int read(uint8_t *buf, size_t size);
    int peek();
    void flush();
    void stop();
    uint8_t connected();

    operator bool()
    {
        return connected();
    }
    WiFiClient & operator=(const WiFiClient &other);
    bool operator==(const bool value)
    {
        return bool() == value;
    }
    bool operator!=(const bool value)
    {
        return bool() != value;
    }
    bool operator==(const WiFiClient&);
    bool operator!=(const WiFiClient& rhs)
    {
        return !this->operator==(rhs);
    };

    virtual int fd() const;

    int setSocketOption(int option, char* value, size_t len);
    int setSocketOption(int level, int option, const void* value, size_t len);
    int setOption(int option, int *value);
    int getOption(int option, int *value);
    int setTimeout(uint32_t seconds) override;
    int setNoDelay(bool nodelay);
    bool getNoDelay();

    IPAddress remoteIP() const;
    IPAddress remoteIP(int fd) const;
    uint16_t remotePort() const;
    uint16_t remotePort(int fd) const;
    IPAddress localIP() const;
    IPAddress localIP(int fd) const;
    uint16_t localPort() const;
    uint16_t localPort(int fd) const;

    //friend class WiFiServer;
    using Print::write;
};

#endif /* _WIFICLIENT_H_ */
#

i tried to add overrides as ChatGPT recommanded me, but it generates error for every method that is not a direct child (works for all methods from ESPLwIPClient , but not from Client)

minor bane
#
int setTimeout(uint32_t seconds) override;

🤨 It uses C++11 here, but not for any of the other overrides.

frozen summit
#

a versionning issue, since i just letted the whole PlatformIO handling those i don't really know what VCC i am on

#

if what i'm saying has any sense xD i'm barely new at CPP

#

PACKAGES:

  • framework-arduinoespressif32 @ 3.20016.0 (2.0.16)
  • tool-esptoolpy @ 1.40501.0 (4.5.1)
  • toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
minor bane
#

Can you post your version of "WiFi.h"?

frozen summit
#

2.0.0

#

Dependency Graph
|-- Freenove VK16K33 Lib @ 1.0.0
|-- Freenove WS2812 Lib for ESP32 @ 1.0.6
|-- IRremote @ 4.4.0
|-- Adafruit SSD1306 @ 2.5.10
|-- Adafruit GFX Library @ 1.11.9
|-- Adafruit BusIO @ 1.16.1
|-- BasicIOStream @ 1.0.1
|-- LiquidCrystal @ 1.5.0
|-- ArduinoHttpClient @ 0.6.0
|-- SPI @ 2.0.0
|-- Wire @ 2.0.0
|-- Freenove 4WD modules @ 1.0.5
|-- WiFi @ 2.0.0

#

from the dep graph

minor bane
#

I mean; the file you have.
I can only see the GH version.

frozen summit
#

ohh

#

version in that way

#
/*
 WiFi.h - esp32 Wifi support.
 Based on WiFi.h from Arduino WiFi shield library.
 Copyright (c) 2011-2014 Arduino.  All right reserved.
 Modified by Ivan Grokhotkov, December 2014

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef WiFi_h
#define WiFi_h

#include <stdint.h>

#include "Print.h"
#include "IPAddress.h"
#include "IPv6Address.h"

#include "WiFiType.h"
#include "WiFiSTA.h"
#include "WiFiAP.h"
#include "WiFiScan.h"
#include "WiFiGeneric.h"

#include "WiFiClient.h"
#include "WiFiServer.h"
#include "WiFiUdp.h"

class WiFiClass : public WiFiGenericClass, public WiFiSTAClass, public WiFiScanClass, public WiFiAPClass
{
private:
    bool prov_enable;
public:
    WiFiClass()
    {
        prov_enable = false;
    }

    using WiFiGenericClass::channel;

    using WiFiSTAClass::SSID;
    using WiFiSTAClass::RSSI;
    using WiFiSTAClass::BSSID;
    using WiFiSTAClass::BSSIDstr;

    using WiFiScanClass::SSID;
    using WiFiScanClass::encryptionType;
    using WiFiScanClass::RSSI;
    using WiFiScanClass::BSSID;
    using WiFiScanClass::BSSIDstr;
    using WiFiScanClass::channel;
public:  
    void printDiag(Print& dest);
    friend class WiFiClient;
    friend class WiFiServer;
    friend class WiFiUDP;
    void enableProv(bool status);
    bool isProvEnabled();
};

extern WiFiClass WiFi;

#endif

frozen summit
#

but nothing new

#

so ignore it exists it's just me that added it

minor bane
frozen summit
#

it's so weird it doesn't fit with the actual gh repo

#

when i tried to manually inject the official thing

#

it requires some ESPIDF libraries where i'm purely on Arduino framework

minor bane
#

I am stumped.
The code looks correct.

frozen summit
#

Yeah

#

That’s the weirdest

minor bane
#

Wait, wait, wait.
Can you do this....

class ESPLwIPClient : public Client
{
public:
  using Client::connect;  // add this
  virtual int connect(IPAddress ip, uint16_t port, int32_t timeout) = 0;
  virtual int connect(const char *host, uint16_t port, int32_t timeout) = 0;
  virtual int setTimeout(uint32_t seconds) = 0;
};
#

This "fork" of the library is cursed.

frozen summit
#
 class WiFiClient : public ESPLwIPClient
       ^~~~~~~~~~
In file included from C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/cores/esp32/arduino.h:193,
                 from .pio/libdeps/esp-wrover-kit/Freenove VK16K33 Lib/src/Freenove_VK16K33_Lib.h:6,
                 from lib/Freenove/src/Car_Emotion.h:4,
                 from src/main.cpp:1:
C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/cores/esp32/Client.h:29:17: note:      'virtual int Client::connect(IPAddress, uint16_t)'
     virtual int connect(IPAddress ip, uint16_t port) =0;
                 ^~~~~~~
C:/Users/nicol/.platformio/packages/framework-arduinoespressif32/cores/esp32/Client.h:30:17: note:      'virtual int Client::connect(const char*, uint16_t)'
     virtual int connect(const char *host, uint16_t port) =0;```
frozen summit
#

OH F-

#

I FOUND THE SOLUTION

#

@minor bane i replaced all the uint16_t for the client.h to unsigned int

#

and now it works

#

for... some reasons ?

#

2 F-ing DAYS FOR THAT

#

i wanna headslam my desk

#

!solved

nimble sirenBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

frozen summit
#

thank you for your help QwQ

minor bane
#

What?

frozen summit
#

i'm as confused as you

#

it works i won't complain tho

minor bane
#

I never would have guessed that.
You may want to change all those to std::uint16_t.
I am guessing this library is making its own typedefs somewhere.

#

(#include <cstdint>)

#

Still think this fork is cursed.

frozen summit
#

well, for now i'm just discovering all the cpp world, and i'm trying to make something that works before making it clean

#

so that's gonna be a task for later

minor bane
#

Sure. I am signing off for a few hours. Jobs to do.
I'll be back later. Maybe.

frozen summit
#

seeya, thank you for the help

minor bane
#

Well, I didn't really do anything.

frozen summit
#

well, at least you tried so thank you still xD

past grail
#

C programmer race inferior

frozen summit
#

uhhh