Why error multiple definition

Although you did write the definition of that variable only once, you did so in a header file.

The header file radioStats.h is included by displayName.h, which is included by displayName.cpp and main.cpp.

Hence when the Cpp files are compiled, each resulting object file will have the definition of that variable in it, leading to a “multiple definition” error when all object files are linked together to the firmware.elf.

That’s why a variable is never defined in a header file, only declared. The definition of it has to be put in one single .cpp file, so that only that object file which is created from it, and not multiple other files.

You can fix the error by moving the struct definition in a new file, e.g. src/radioStats.cpp, which includes radioStats.h (to be able to reference the struct type). Then, the radioStats.h just needs to declare the existence of that variable with

extern struct RadioStation sRadioStation[MAX_STATIONS];

See e.g. related topics like A new PlatformIO user coding wrong, getting multiple definition & first defined here errors - #2 by maxgerhardt