Multiple include

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

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

You are correct to have opened an issue at Multiple include. This is a library issue. The header file #includes the implementation of the class,

and so if multiple compilation units (.c/.cpp files) include the AsyncUDP_WT32_ETH01.h header, the implementation will be duplicated as well. This happens in your example through UdpListener.h including AsyncUDP_WT32_ETH01.h and then main.cpp and UdpListener.cpp include this header, so it’s game over.

A possible fix might be removing the #include <AsyncUDP_WT32_ETH01_Impl.h> from AsyncUDP_WT32_ETH01_Impl.h and renaming AsyncUDP_WT32_ETH01_Impl.h to AsyncUDP_WT32_ETH01_Impl.cpp.

Thank you for the quick confirmation.

I’ve moved the implementation in .cpp files. Please use the platformio.ini

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps = https://github.com/maxgerhardt/AsyncUDP_WT32_ETH01.git

delete the .pio folder of the project and build again.

Thank you, that took care of the issue.

I have the same issue (error message) but use Arduino, how does one fix it for Arduino? The above lin_deps just create major compile issues

I really need to see the full platformio.ini and source code to judge your situation.