main.cpp.o:(.bss.AsyncElegantOTA+0x0): multiple definition of `AsyncElegantOTA’

Dear all,
I have a problem with `AsyncElegantOTA’ when not included in the main.cpp file.
I’ve created and Serverm.h and Server.cpp file where I’d like to put my webserver, websocket and OTA code.
Webserver and Websockets are working ok but as soon as I’m adding few line of code of AsyncElegantOTA I get the multiple definition error code.

#ifndef AElegantOTA_h
#define AElegantOTA_h
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>

void WebServerInit();

#include “Serverm.h”
#define HTTP_PORT 80
AsyncWebServer server(HTTP_PORT);

void WebServerInit() {
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { // Default simple page
request->send(200, “text/plain”, “Hi! I am ESP8266.”);

AsyncElegantOTA.begin(&server); // Start ElegantOTA

#include <Arduino.h>
#include “Serial.h”
#include “WiFim.h”
#include “FSm.h”
#include “Serverm.h”

void setup(void) {

Appreciate if you could give me an hint.

What happens when you move this line in Servem.cpp?

This library is badly written. In the header file, they instantiate an object of the class they previously defined with

the correct way would be to just declare it as extern and then create a .cpp file where the object is instantiated.

Because the library is written that way, it forces you that you only #include <AsyncElegentOTA.h> in one .cpp file, not in a .h file that is included by multiple files. If the include appears in multiple .cpp files (e.g. because multipe .cpp files include a header that includes AsyncElegantOTA.h, which is exactly your case), the object creation will be duplicated accross those .cpp files, and you receive the error above.

1 Like

It compiles without error.
It seems working

Great hint.
Your suggestion is to modify the library?
Do you know better OTA for ESP8266?


1 Like