khoih-prog / WebSockets2_Generic

A WebSocket Server and Client library for Arduino, based on RFC6455, for writing modern Websockets applications. Now support ESP8266, ESP32 (including ESP32-S2 Saola, AI-Thinker ESP-12K, WT32_ETH01, etc.), nRF52, SAMD21, SAMD51, SAM DUE, STM32F/L/H/G/WB/MP1, Teensy, RP2040-based, etc. boards, with WiFiNINA, Teensy 4.1 NativeEthernet/QNEthernet, Ethernet W5x00 / ENC28J60 / LAN8742A / LAN8720, ESP8266 / ESP32-AT modules/shields, as well as SINRIC / Alexa / Google Home
GNU General Public License v3.0
81 stars 30 forks source link

multiple definition of `websockets2_generic::WebsocketsServer::....' #15

Closed OOHehir closed 3 years ago

OOHehir commented 3 years ago

Hello,

Firstly thanks for the work you've put into the library.

I'm using ver 1.1 of your library in conjunction with Sloeber on Eclipse on a 8266.

I have an issue which seems related to a closed bug report (https://github.com/khoih-prog/WebSockets2_Generic/issues/3) but I haven't been able to solve it with your proposed solution.

I have the following setup:

sensor.ino


#include "LwDevice.h"
#include <Arduino.h>

lwDevice lwNode;

setup()

loop()

lwDevice.cpp


#include "LwDevice.h"
#include <Arduino.h>

using namespace std;

namespace lw {

int LwDevice::sendSocketJSON(){

//websockets2_generic::WebsocketsClient socket; Compiles ok if initialised here
do socket stuff...

}
}

lwDevice.h

#include <WebSockets2_Generic.h>

namespace lw {

class LwDevice {
private:
websockets2_generic::WebsocketsClient socket; // lots of multiple def errors when init here

}
}

So when creating the object inside the sendSocketJSON() it compiles correctly, moving it to the class causes multiple definition errors. E.g: /opt/eclipse/arduinoPlugin/packages/esp8266/hardware/esp8266/2.7.0/libraries/EEPROM/EEPROM.cpp:108: multiple definition of EEPROMClass::write(int, unsigned char)'; ./libraries/ESP_EEPROM/src/ESP_EEPROM.cpp.o:/opt/eclipse/arduinoPlugin/libraries/ESP_EEPROM/2.1.1/src/ESP_EEPROM.cpp:296: first defined here /opt/eclipse/arduinoPlugin/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: ./libraries/EEPROM/EEPROM.cpp.o: in functionEEPROMClass::commit()': /opt/eclipse/arduinoPlugin/packages/esp8266/hardware/esp8266/2.7.0/libraries/EEPROM/EEPROM.cpp:127: multiple definition of EEPROMClass::commit()'; ./libraries/ESP_EEPROM/src/ESP_EEPROM.cpp.o:/opt/eclipse/arduinoPlugin/libraries/ESP_EEPROM/2.1.1/src/ESP_EEPROM.cpp:339: first defined here /opt/eclipse/arduinoPlugin/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: ./libraries/EEPROM/EEPROM.cpp.o: in functionEEPROMClass::end()': /opt/eclipse/arduinoPlugin/packages/esp8266/hardware/esp8266/2.7.0/libraries/EEPROM/EEPROM.cpp:81: multiple definition of EEPROMClass::end()'; ./libraries/ESP_EEPROM/src/ESP_EEPROM.cpp.o:/opt/eclipse/arduinoPlugin/libraries/ESP_EEPROM/2.1.1/src/ESP_EEPROM.cpp:248: first defined here /opt/eclipse/arduinoPlugin/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: ./libraries/EEPROM/EEPROM.cpp.o:/opt/eclipse/arduinoPlugin/packages/esp8266/hardware/esp8266/2.7.0/libraries/EEPROM/EEPROM.cpp:156: multiple definition ofEEPROM'; ./libraries/ESP_EEPROM/src/ESP_EEPROM.cpp.o:/opt/eclipse/arduinoPlugin/libraries/ESP_EEPROM/2.1.1/src/ESP_EEPROM.cpp:528: first defined here

Any pointers would be gratefully appreciated,

ark02 commented 3 years ago

I am in the same boat as you, just started using lib, same issues I'm using Platformio

In another issue, he added the instructions to readme: https://github.com/khoih-prog/AsyncHTTPRequest_Generic#howto-fix-multiple-definitions-linker-error

But these were unclear to me...

What I ended up doing was:

khoih-prog commented 3 years ago

Thanks for your interests in the library and many thanks to @ark02 for your help.

Without the MRE, I'm afraid nobody can help you, especially with your seemingly complicated project.

It also seems that the error messages are relating to certain EEPROMClass you're using, nothing relating to this library.

multiple definition of EEPROMClass::commit()';

Carefully study solved issue : multiple definition of `websockets2_generic::WebsocketsServer::~WebsocketsServer()' in websocket2_generic library #3 to understand why the issue happens. Then I think you can fix it yourself with your good knowledge to do such a complicated project. Ask yourself a question why many people have been using this library without that issue, then restructure your code.

Another way to ask for help is to post the issue in ArduinoWebsockets because you're using ESP8266, certainly after you've tried to compile using that library and get the same error.

I'm closing the issue now, and will reopen whenever you prove that the issue is a bug of this library.

Good Luck,