This is the error message:
pio/build/esp32doit-devkit-v1/libcc7/libDisplayName.a(displayName.cpp.o):(.data.sRadioStation+0x0): multiple definition of `sRadioStation’
.pio/build/esp32doit-devkit-v1/src/main.cpp.o:(.data.sRadioStation+0x0): first defined here
But, AFAIK, I never defined that variable twice (or more).
Some help will be most useful, thanks in advance.
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