khoih-prog / Ethernet_Generic

Simple Ethernet library for AVR, AVR Dx, Portenta_H7, Teensy, SAM DUE, SAMD21, SAMD51, STM32F/L/H/G/WB/MP1, nRF52 and RASPBERRY_PI_PICO boards using Ethernet shields W5100, W5200, W5500, W5100S, W6100. With this library you can use the Arduino Ethernet (shield or board) to connect to Internet to provides both Client and server functionalities.
42 stars 22 forks source link

Multiple Definition when linking #5

Closed aaron-neal closed 2 years ago

aaron-neal commented 2 years ago

Describe the bug

I am have included Ethernet_Generic.h in my main file for starting a webserver. I also have Ethernet_Generic included in another header file for a Modbus TCP class.

On compiling I get many multiple definition errors such as c:/users/??????/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio/build/stm32-5mi/src/modbus/ModbusTCPSlave.cpp.o:(.bss._ZN10W5100Class4chipE+0x0): multiple definition of `W5100Class::chip'; .pio/build/stm32-5mi/src/main.cpp.o:(.bss._ZN10W5100Class4chipE+0x0): first defined here

Any help would be appreciated.

Expected behavior

When using previous Ethernet library, everything compiled as normal. Previous Library

Information

aaron-neal commented 2 years ago

It looks like using inline on functions clears them from the multiple definitions list. e.g.:

inline int DNSClient::inet_aton(const char* address, IPAddress& result)

khoih-prog commented 2 years ago

Did you try and follow the instructions in multiFileProject example to avoid Multiple Definitions

This library was used in many more complex projects / libraries without error by not carelessly and blindly including any h file.

Please spend some time to research which libraries is using and how to have some ideas, if necessary.

I'm sure won't go back to the old cpp style.

Good Luck,

aaron-neal commented 2 years ago

Thank you @khoih-prog, I had not seen that example. Got me on my way. Cheers.