smarmengol / Modbus-Master-Slave-for-Arduino

Modbus Master-Slave library for Arduino
GNU Lesser General Public License v2.1
473 stars 328 forks source link

'Multiple definition of' error when including in multiple files. #63

Open Lodevd opened 2 years ago

Lodevd commented 2 years ago

When including this library in multiple files you get the the following error(s):

(.text+0x0): multiple definition of `Modbus::Modbus(unsigned char, Stream&, unsigned char)'

This is easily solved with the following modifications:

1) Placing a "ifndef" around the header code.

ifndef MODBUS_RTU_H

define MODBUS_RTU_H

....

endif

2) creating a ModbusRtu.cpp file to split definition from declaration. All code down from the next line must be moved to the .cpp file. / PUBLIC FUNCTIONS____ /

3) and obviously include the header file at the top of the .cpp file. :)

include