I’m having some trouble on my Smarthome ESP32 project.
First of all, the link to the github repository:
After educating myself about propper C++ coding im currently applying a propper code style guideline to the code at the moment, if you want to take a look at the most current code check out “fb_9_refactor_codebase”.
The project uses global instances of two classes, a logger that provides formatted outputs and a system timer that syncs time via network to correctly timestamp received signals.
Before refactoring (having all code inside of the .h files) we were able to simply write
ConsoleLogger logger; at the end of the
console_logger.h and include the file in every other file and use
logger.println() to print messages.
Now, however, when doing this we get a ton of
multiple definition of 'logger'-Erros when the linker tries to link all the files, because there is a instance of ConsoleLogger called logger created for every seperate .cpp-File created.
static works, but there is still an instance for every .cpp file created, which in case of the logger bricks format (since the indentation is not synced between classes) and the timer doesn’t work at all.
The propper way to do this seems to be using extern - but doing so creates the following error:
Linking .pio/build/esp32cam/firmware.elf .pio/build/esp32cam/src/connectors/connectors.cpp.o:(.literal._ZN12IR_Connector9sendRawIREPKth+0x4): undefined reference to `logger' collect2: error: ld returned 1 exit status
The logger is included in the connectors.cpp.
Im really thankful for every tip anyone of you can provide, a already got some great help with another issue
Thanks in advance,