Skip to content

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

@Lodevd

Description

@Lodevd

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 <ModbusRtu.h>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions