This is a common problem when people just declare their global variables in a .h
file and include it from multiple .cpp
files – you have to use a extern
declaration (in header) and definition (in cpp file) pattern to do global variable sharing correctly. This has been discussed a lot of times in the forum already, see e.g.
- Mutiple definition & first defined here error in own libray
- Tutorial for creating multi cpp file arduino project - #19 by peekpt
- c++ - How do I use extern to share variables between source files? - Stack Overflow
If you still have problems, post the complete source code with error message.