khoih-prog / AsyncUDP_WT32_ETH01

Fully Asynchronous UDP Library for WT32_ETH01 (ESP32 + LAN8720). The library is easy to use and includes support for Unicast, Broadcast and Multicast environments.
GNU General Public License v3.0
17 stars 4 forks source link

Multiple definitions #1

Closed wmarchewka closed 2 years ago

wmarchewka commented 2 years ago

Using platformio on a mac, trying to get this very simple code to compile. I get issues with the linker.


main.cpp


#include "UdpListener.h"
UdpListener udp_server;

void setup()
{
    delay(1);
}

void loop()
{
    delay(1);
}

UdpListener.h


#pragma once
#ifndef UDPLISTENER_H
#define UDPLISTENER_H

#include <AsyncUDP_WT32_ETH01.h>

class UdpListener
{

private :

public:
    UdpListener();
};
#endif

UdpListener.cpp


#include "UdpListener.h"

UdpListener::UdpListener()
{
}

Verbose mode can be enabled via -v, --verbose option

CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (4.4.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 3.20003.0 (2.0.3) 
 - tool-esptoolpy @ 1.30300.0 (3.3.0) 
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 41 compatible libraries
Scanning dependencies...
Dependency Graph
|-- UdpListener
|   |-- Free
|   |-- AsyncUDP_WT32_ETH01 @ 2.0.3
|   |   |-- WebServer_WT32_ETH01 @ 1.4.1
|   |   |   |-- Ethernet @ 2.0.0
|   |   |   |   |-- WiFi @ 2.0.0
|   |   |   |-- WebServer @ 2.0.0
|   |   |   |   |-- WiFi @ 2.0.0
|   |   |   |   |-- FS @ 2.0.0
|   |   |   |-- WiFi @ 2.0.0
Building in release mode
Compiling .pio/build/myenv/src/main.cpp.o
In file included from .pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01.h:64,
                 from lib/UdpListener/UdpListener.h:5,
                 from src/main.cpp:3:
.pio/libdeps/myenv/WebServer_WT32_ETH01/src/WebServer_WT32_ETH01.h:50:4: warning: #warning Using ESP32 architecture for WebServer_WT32_ETH01 [-Wcpp]
   #warning Using ESP32 architecture for WebServer_WT32_ETH01
    ^~~~~~~
Compiling .pio/build/myenv/lib2c4/UdpListener/UdpListener.cpp.o
In file included from .pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01.h:51,
                 from lib/UdpListener/UdpListener.h:5,
                 from lib/UdpListener/UdpListener.cpp:1:
/Users/waltermarchewka/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/tcpip_adapter/include/tcpip_adapter.h:15:2: warning: #warning "This header is deprecated, please use new network related API in esp_netif.h" [-Wcpp]
 #warning "This header is deprecated, please use new network related API in esp_netif.h"
  ^~~~~~~
In file included from .pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01.h:64,
                 from lib/UdpListener/UdpListener.h:5,
                 from lib/UdpListener/UdpListener.cpp:1:
.pio/libdeps/myenv/WebServer_WT32_ETH01/src/WebServer_WT32_ETH01.h:50:4: warning: #warning Using ESP32 architecture for WebServer_WT32_ETH01 [-Wcpp]
   #warning Using ESP32 architecture for WebServer_WT32_ETH01
    ^~~~~~~
Archiving .pio/build/myenv/lib2c4/libUdpListener.a
Indexing .pio/build/myenv/lib2c4/libUdpListener.a
Linking .pio/build/myenv/firmware.elf
/Users/waltermarchewka/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/myenv/lib2c4/libUdpListener.a(UdpListener.cpp.o): in function `AsyncUDPMessage::write(unsigned char)':
/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:401: multiple definition of `AsyncUDPMessage::write(unsigned char)'; .pio/build/myenv/src/main.cpp.o:/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:401: first defined here
/Users/waltermarchewka/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/myenv/lib2c4/libUdpListener.a(UdpListener.cpp.o): in function `AsyncUDPMessage::flush()':
/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:436: multiple definition of `AsyncUDPMessage::flush()'; .pio/build/myenv/src/main.cpp.o:/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:436: first defined here
/Users/waltermarchewka/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/myenv/lib2c4/libUdpListener.a(UdpListener.cpp.o): in function `AsyncUDPPacket::available()':
/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:540: multiple definition of `AsyncUDPPacket::available()'; .pio/build/myenv/src/main.cpp.o:/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:540: first defined here
/Users/waltermarchewka/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/myenv/lib2c4/libUdpListener.a(UdpListener.cpp.o): in function `AsyncUDPPacket::read()':
/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:567: multiple definition of `AsyncUDPPacket::read()'; .pio/build/myenv/src/main.cpp.o:/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:567: first defined here
/Users/waltermarchewka/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/myenv/lib2c4/libUdpListener.a(UdpListener.cpp.o): in function `AsyncUDPPacket::peek()':
/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:579: multiple definition of `AsyncUDPPacket::peek()'; .pio/build/myenv/src/main.cpp.o:/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:579: first defined here
/Users/waltermarchewka/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/myenv/lib2c4/libUdpListener.a(UdpListener.cpp.o): in function `AsyncUDPPacket::flush()':
/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:591: multiple definition of `AsyncUDPPacket::flush()'; .pio/build/myenv/src/main.cpp.o:/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:591: first defined here
/Users/waltermarchewka/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/myenv/lib2c4/libUdpListener.a(UdpListener.cpp.o): in function `AsyncUDPPacket::write(unsigned char)':
/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:716: multiple definition of `AsyncUDPPacket::write(unsigned char)'; .pio/build/myenv/src/main.cpp.o:/Users/waltermarchewka/Documents/PlatformIO/Projects/ESP32_LOW_POWER_RELAY/.pio/libdeps/myenv/AsyncUDP_WT32_ETH01/src/AsyncUDP_WT32_ETH01_Impl.h:716: first defined here
/Users/waltermarchewka/.platformio/packages/toolchain-xtensa-esp32/bi
maxgerhardt commented 2 years ago

Cross-posted to https://community.platformio.org/t/multiple-include/28287

khoih-prog commented 2 years ago

Hi @wmarchewka

This library is current using h-only style, and to use it correctly, you have either use the h-only style for your code or to include the library h files a little bit more carefully.

For example

A) h-only style

1. main.cpp

#include "UdpListener.h"

UdpListener udp_server;

void setup()
{
  delay(1);
}

void loop()
{
  delay(1);
}

2. UdpListener.h

#pragma once

#ifndef UDPLISTENER_H
#define UDPLISTENER_H

#include <AsyncUDP_WT32_ETH01.h>

class UdpListener
{

  private :

  public:
    UdpListener();
};

#include "UdpListener_Impl.h"

#endif

3. UdpListener_Impl.h

#pragma once

#ifndef UDPLISTENER_IMPL_H
#define UDPLISTENER_IMPL_H

UdpListener::UdpListener()
{
}

#endif

Also have a look at Fixed linker errors when included in multiple .cpp files #1

Anyway, I'll convert this outdated library later to use the same style as AsyncUDP_Teensy41 library, then you can use the example similar to multiFileProject

Thanks to @maxgerhardt for the providing the solution in https://community.platformio.org/t/multiple-include/28287

wmarchewka commented 2 years ago

Thanks all !

khoih-prog commented 2 years ago

Hi @wmarchewka

Check the new AsyncUDP_WT32_ETH01 release v2.1.0 and the multiFileProject


Releases v2.1.0

  1. Fix multiple-definitions linker error. Check Multiple definitions #1
  2. Add example multiFileProject to demo for multiple-file project to avoid multiple-definitions linker error