Reading structs from different places

Hello everybody!

Im working on a project involving a whole bunch of different modules, so im trying to work out a elegant code to facilitate everything while still being easy to follow and so on.

So im writing a bunch of classes to take care of its piece of the pie, allowing me to do complex things with a "className.doThis(value);".

Keep in mind, i chose this route in order to learn classes and so on, not because i MUST have them here.. :stuck_out_tongue:

Now, my problem arises when i try to use my classes to modify a structure that contains a number of variable containers, that i wish to read from the main loop.

I usually get error: multiple definitions of "TimeStruct" in the compiler, even tho i included the _struct.h where needed and there is a include-guard in the _structs.h.

So could anyone enlighten me, how would i include and modify a structure from a function/class so i can read/write to that structure from main loop?

The project is already divided into separate header and source documents, im probably just failing to link everything together properly..

My project organization is as follows:
mainProject.ino, classDoc.h, classDoc.cpp, classDoc_structs.h

the .ino contains all the #include´s, void setup, loop and so on.

classDoc_structs.h contains the structure definition and declaration.

the classDoc´s #include the _structs.h and modifies its members.

The main loop uses the _structs.h struct members as variables in the code.
The loop also calls for class members that updates the struct members outside of the loop.

mainProject.ino:

#include "time.h"                  // classDoc
#include "timeStructs.h"        //   structs for Time

myTime Time;

void setup() {
Time.begin();
}

void loop() {
Time.update();
}

time.h:

#ifndef time_h
#define time_h

#include "Arduino.h"

class myTime {
public: 
  void begin(void);
  void update(void);
  bool compare(uint32_t _last, uint32_t _limit);

private:
  void timeSetup(void);
  void check(void);
};

#endif // time_h

time.cpp:

#include "time.h"
#include "time_structs.h"

void myTime::begin(void) {
  timeSetup();
  tick();
  update();
}

void myTime::update(void) {
  tick();
  TimeStruct.lastUpdate = TimeStruct.Now;
}

bool myTime::compare(uint32_t _last, uint32_t _limit) {
  bool result = false;
  if ( TimeStruct.Now - _last >= _limit ) {
    result = true;
  }
  
  return result;
}

time_structs.h:

#ifndef time_structs_h
#define time_structs_h
#include "Arduino.h"

struct timeStruct {
  uint32_t Now;
  uint32_t lastUpdate;
} timeStruct ;
struct timeStruct TimeStruct = {
  0,
  0
};
#endif // end time_structs_h

@MarkT provided this for someone who was having a very similar problem...