khoih-prog / EthernetWebServer

This is simple yet complete WebServer library for AVR, AVR Dx, Portenta_H7, Teensy, SAM DUE, SAMD21/SAMD51, nRF52, STM32, RP2040-based, etc. boards running Ethernet shields. The functions are similar and compatible to ESP8266/ESP32 WebServer libraries to make life much easier to port sketches from ESP8266/ESP32. Coexisting now with `ESP32 WebServer` and `ESP8266 ESP8266WebServer` libraries. Ethernet_Generic library is used as default for W5x00 with custom SPI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error on PlatformIO "multiple definition of `EthernetWebServer::.."

EmperorArthur opened this issue · comments

Hello,

Due to the way the code is written, #include <EthernetWebServer.h> can never be used in a header file.

It always results in a multiple definition error.

I believe the problem can be traced to these two lines in "EthernetWebServer.h"

#include "EthernetWebServer-impl.h"
#include "Parsing-impl.h"

It may be better to convert the "*-impl.h" files to instead be ".cpp" files, which are linked at compile time.

Hi,

Thanks for your interests in the library and your Feature Request: Add a RequestHandler subclass which passes the server to the function #27

For more info on why and how to use correctly or fix this, check

  1. HOWTO Fix Multiple Definitions Linker Error
  2. Fixed linker errors when included in multiple .cpp files #1
  3. and many similar posts here and there

I'll consider to add cpp version besides the h-only version later if there are more requests as this issue happens only in rare use-cases or when inclusion is not carefully considered.

More notes

I don't know if you go through the examples before writing this line

Due to the way the code is written, #include <EthernetWebServer.h> can never be used in a header file.

For examples #include <EthernetWebServer.h> @ line 344 of defines.h

or can be used in other library code

For example #include <EthernetWebServer.h> @ line 104 of Ethernet_Manager.h of Ethernet_Manger Library

Hello,

Apologies for not being more clear. I meant to say, "#include <EthernetWebServer.h> can never be included in a header file which is included by more than one ".cpp" file."

We were unaware of the "AsyncHTTPRequest_Generic library" until now, and thank you for responding to our question.
I had never even heard of your . I see your response to my suggestion there.

Unfortunately, a requirement of the project is that someone can download the code and follow the standard PlatformIO build instructions to run it, therefore modifying the library files is nor allowed. In addition, as this is a relatively large code base, eschewing C/C++ convention and converting everything to "-impl.h" files is also a hard pass.

With this in mind, we have determined that your library is not suitable for a production environment, and will continue searching for alternatives.

Thank you for your time.