#Cannot declare variable 'server' to be of abstract type 'EthernetServer'

139 messages ยท Page 1 of 1 (latest)

jolly karma
#

Hello guys
I have a big problem with my Ethernet Webserver. Wifi runs perfect, but Ethernet wont work at all.
I have the W5500 Chip and no matter what i do, i always get this Error:

Compilation error: cannot declare variable 'server' to be of abstract type 'EthernetServer'

The Server ist for a project at work and is very important.
Anyone have a fix for it maybe? ๐Ÿ™‚
Thanks and Greetings

balmy dewBOT
#

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.

jolly karma
#

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

class MyServer : public EthernetServer {
public:
MyServer(uint16_t port) : EthernetServer(port) {
}
};

// MAC address for your Ethernet shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// IP address for your ESP32
IPAddress ip(192, 168, 8, 120);
// Subnet mask for your network
IPAddress subnet(255, 255, 255, 0);
// Gateway IP for your network
IPAddress gateway(192, 168, 8, 1);

// Ethernet Server on port 80 (http port)

void setup() {
// Initializing serial port for debugging purposes
Serial.begin(9600);
EthernetServer server(80);
while (!Serial) {
; // Wait for serial port to connect
}

// Initializing ethernet device
Ethernet.init(15); // Use Ethernet.init(pin) to configure the CS pin
Ethernet.begin(mac, ip, gateway, subnet);

// 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 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");

waxen crest
#

thanks for opening the thread ๐Ÿ‘

#

so, as I said

jolly karma
#

Thank you! ๐Ÿ™‚

#

You maybe have a fix for it? Im really desperate ๐Ÿ˜„

waxen crest
#

EthernetServer must have member functions that don't have an implementation. You have to look for member functions marked virtual ... = 0; in the EthernetServer class, including in EthernetServer's base classes. Then you need to make sure all such functions are overridden and have an implementation in EthernetServer (or in one of its base classes). If they don't, EthernetServer is an abstract type and cannot be instantiated, hence the error.

#

if you're using a network library, this should all be stated in the documentation and you should refer to that primarily

jolly karma
#

So if i understand it right, i have to go to my library, for example Ethernet2 and look for the Ethernetserver (C++ File) and in that file looke for "virtual ... = 0"?

waxen crest
#

if you are indeed using a library then the first thing you should do is reading the documentation

#

this has to be explained somewhere, possibly with examples if you're lucky

jolly karma
#

The problem is, i run the Example from the library im using, and even in the example i get the same error code

#

So the example simply doesnt work

waxen crest
#

well then maybe the library is fucked up yamikek

#

that would be unfortunate

jolly karma
#

I tried Ethernet.h, Ethernet2.h and Ethernet3.h, in every library i get the same error code even with the examples

waxen crest
#

what library is it

jolly karma
#

Ethernet library

#

Ethernet2 library

#

Ethernet3 library

waxen crest
#

are those the name of it

jolly karma
#

yes i guess so

#

well yeah

waxen crest
#

can you post a link to them, I can't find them

jolly karma
#

one moment

waxen crest
#

first issue right there

jolly karma
#

thats the one i tried next

#

The "Ethernet" library

#

But its the same issue

waxen crest
#

and are you certain that the EthernetServer server; variable that you're declaring is actually of the type EthernetServer from the official Arduino Ethernet library?

#

sounds to me like a potential issue

jolly karma
#

I dont really know what you mean ๐Ÿ˜ฆ I hope you can still help me.
I just installed the official Arduino Ethernet library and try to run this example.
Then this Error occured which i cant get rid of and dont find anything on the internet about this problem

waxen crest
#

I don't know how arduino things work unfortunately, but what's your compiler and how do you configure it?

jolly karma
#

I compile it with Arduino IDE

#

Thats the library

waxen crest
#

and does the Arduino IDE allow you to configure include paths?

jolly karma
#

What do you mean exactly? :/

#

oh

#

i think i know what u mean

#

i can open them and modify them. if i understand you correctly

waxen crest
#

include paths are IDE/compiler settings which basically tell where to look for files that you #include in your own source code

#

my guess is that you have an #include "ethernet_server.h" or something that points to the deprecated library rather than to the official one

#

if that turns out to be the case, you need to fix it by correcting your include paths

jolly karma
#

this is the ethernet.h

#

in there i searched for "virtual"

waxen crest
#

yeah I could have a look at that header on the repo, I didn't find any pure virtual functions

#

(those are all virtual, not pure virtual)

#

can you have a look at your include paths?

jolly karma
#

i need to look how to do it

#

or what you mean exactly?
#include SPI.h
and
#include Ethernet.h

#

?

#

Ah

#

i found it i guess

#

i can go to the path yeah

waxen crest
#

I just looked it up, you can't configure include paths in Arduino IDE, it just looks for headers in a standard location

#

can you show the contents of your whole "Libraries" directory please?

jolly karma
#

yes!

#

that is the Ethernet.h

waxen crest
#

So in there, Ethernet is the official Arduino ethernet library, and Ethernet2 and 3 are some kind of spin-offs?

jolly karma
#

Yes right

waxen crest
#

alright

#

can you remove them entirely? yamikek

jolly karma
#

haha

waxen crest
#

from this directory at least

jolly karma
#

i can yeah

#

i move them in a backup folder on my desktop

waxen crest
#

sure

jolly karma
#

so just include the Ethernet libary?

waxen crest
#

yes

jolly karma
#

or also remove it?

#

ok

waxen crest
#

you keep the official Ethernet library

#

now if you recompile does that make it any better

jolly karma
#

i just removed the librarys, i now check again

waxen crest
#

same error then

jolly karma
#

yeah ๐Ÿ˜ฆ

waxen crest
#

is that the top most error?

jolly karma
#

yes

waxen crest
#

like you can't scroll up above the error complaining about server being of abstract type

#

the path of your file looks... weird

jolly karma
#

this is the whole log

waxen crest
#

okay so at least it is including the correct ethernet header

jolly karma
#

yes i checked that already

#

or i think i did ๐Ÿ˜„

#

the file that i sent you, that is the header, right?

#

Ethernet.h?

waxen crest
#

yes

#

what concerns me now is that it tries to explain why it is abstract, namely because there are pure virtual functions and then it... shows the class declaration?

jolly karma
#

so this is the class you were talking about, right?

waxen crest
#

oh don't mind it I read that sideways

#

is says that this function

#

is not implemented in EthernetServer

#

(it's part of EthernetServer's base class Server)

jolly karma
#

ok but this is in the appdata folder right? so its a "tempory" folder? am i right?

#

or do i completly missunderstand this?

waxen crest
#

it's not temporary

#

that seems to be where the arduino core libraries are located

#

so anyway yes in order not to be abstract anymore EthernetServer needs to override void begin(uint16_t port)

#

but EthernetServer only seems to override void begin()

#

that's what causing the issue

#

so all in all this looks like a version mismatch

jolly karma
#

Oh ok

waxen crest
#

because the Ethernet library seems to be expecting support that is not offered by your core libraries

#

maybe update both, I don't know how that goes

jolly karma
#

Can i fix that myself by editing the files somehow? Hope you know what i mean with that

waxen crest
#

maybe you can use it to get up to date libs

waxen crest
#

updating your libs to matching versions is way easier anyway

jolly karma
#

Ok i will try it!! Thank you a lot already!!

#

Im Kinda Desperate because im trying to get the Webserver working for a project at Work and i thought it would be way easier than it actually is.
Wifi Webserver works 100% but IT at our Company dont Like wifi ๐Ÿ˜‚

waxen crest
#

good luck then ๐Ÿ‘

jolly karma
#

Thank you! ๐Ÿ™‚

balmy dewBOT
#

@jolly karma Has your question been resolved? If so, type !solved :)

jolly karma
#

Compilation error: no matching function for call to 'EthernetServer::begin()'

#

I get this Error now, the other one is gone ๐Ÿ™‚

waxen crest
#

well now you've got matching libs at least

#

can you post the line that provokes this error?

#

must only be a matter of providing an argument

jolly karma
#

C:\Users\Brunndan\AppData\Local\Temp.arduinoIDE-unsaved2024227-18340-1ll8nsc.5m5l\sketch_mar27b\sketch_mar27b.ino: In function 'void setup()':
C:\Users\Brunndan\AppData\Local\Temp.arduinoIDE-unsaved2024227-18340-1ll8nsc.5m5l\sketch_mar27b\sketch_mar27b.ino:31:16: error: no matching function for call to 'EthernetServer::begin()'
server.begin();
^
In file included from C:\Users\Brunndan\AppData\Local\Temp.arduinoIDE-unsaved2024227-18340-1ll8nsc.5m5l\sketch_mar27b\sketch_mar27b.ino:2:
c:\Users\Brunndan\Documents\Arduino\libraries\Ethernet\src/Ethernet.h:261:15: note: candidate: 'virtual void EthernetServer::begin(uint16_t)'
virtual void begin(uint16_t port);
^~~~~
c:\Users\Brunndan\Documents\Arduino\libraries\Ethernet\src/Ethernet.h:261:15: note: candidate expects 1 argument, 0 provided

exit status 1

Compilation error: no matching function for call to 'EthernetServer::begin()'

you mean this?

waxen crest
#

yeah

#

just call it like server.begin(0); or whatever you want the port number to be

jolly karma
#

Now im stuck on even more errors ๐Ÿ˜›

waxen crest
#

somehow it's your Ethernet header which still seems to be wrong

#

well not the header, the source file that comes with it

#

it's the call to .begin() in EthernetServer.cpp line 71 which is incorrect

#

I guess just stick a 0 in there too at this point idk lol