I'm struggling to correctly set up a few structs that I want to be able to use across multiple files. I want to save some settings for my microcontroller that can be manipulated in some structs. A main structs holds some main settings and structs with more specific settings.
I have a settings.h, a a.h, and a b.h.
In the settings.h, I have my structs as follows:
#ifndef LT_SETTINGS_H
#define LT_SETTINGS_H
#include "SD_save.h"
struct ASettings {
  IPAddress ip;
  uint16_t port;
  char *user;
  char *password;
};
struct BSettings {
  bool xEnabled;
  bool yEnabled;
  bool zEnabled;
};
struct Settings {
  char *name;
  ASettings a;
  BSettings b;
  bool active;
  bool changed = false;
} settings;
[...]
#endif //LT_SETTINGS_H
In settings.cpp, I want to have methods for saving and loading these settings from an SD card.
In a.h, I have methods relevant to A which need parameters from the ASettings. Something similar goes for b.h and the BSettings.
I want to be able to manipulate both the ASettings in a.h and the BSettings in b.h.
How do I accomplish this? I've played around with externs, typedefs, the different settings being in the respective header files, but I can't get it to compile.
If this is a stupid idea to begin with and there is a better solution, please let me know. I have the feeling I'm approaching this incorrectly to begin with.
EDIT 1:
So far, I have only included the settings.h in a.h and b.h and I'm getting a lot of multiple definition errors:
libraries/l/a.cpp.o:(.bss.aSettings+0x0): multiple definition of `aSettings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.aSettings+0x0): first defined here
libraries/l/a.cpp.o:(.bss.settings+0x0): multiple definition of `settings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.settings+0x0): first defined here
libraries/l/a.cpp.o:(.bss.bSettings+0x0): multiple definition of `bSettings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.bSettings+0x0): first defined here
libraries/l/sensors.cpp.o:(.bss.bSettings+0x0): multiple definition of `bSettings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.bSettings+0x0): first defined here
libraries/l/sensors.cpp.o:(.bss.aSettings+0x0): multiple definition of `mqttSettings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.aSettings+0x0): first defined here
libraries/l/sensors.cpp.o:(.bss.settings+0x0): multiple definition of `settings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.settings+0x0): first defined here
libraries/l/settings.cpp.o:(.bss.aSettings+0x0): multiple definition of `aSettings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.aSettings+0x0): first defined here
libraries/l/settings.cpp.o:(.bss.settings+0x0): multiple definition of `settings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.settings+0x0): first defined here
libraries/l/settings.cpp.o:(.bss.bSettings+0x0): multiple definition of `sensorSettings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.bSettings+0x0): first defined here
libraries/l/webconf.cpp.o:(.bss.aSettings+0x0): multiple definition of `mqttSettings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.aSettings+0x0): first defined here
libraries/l/webconf.cpp.o:(.bss.settings+0x0): multiple definition of `settings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.settings+0x0): first defined here
libraries/l/webconf.cpp.o:(.bss.bSettings+0x0): multiple definition of `bSettings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.bSettings+0x0): first defined here
collect2: error: ld returned 1 exit status
exit status 1
(I also have b.h included in webconf.h)
EDIT 2:
I changed the initial code a little bit, reducing the compiler errors to this:
libraries/l/a.cpp.o:(.bss.settings+0x0): multiple definition of `settings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.settings+0x0): first defined here
libraries/l/sensors.cpp.o:(.bss.settings+0x0): multiple definition of `settings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.settings+0x0): first defined here
libraries/l/settings.cpp.o:(.bss.settings+0x0): multiple definition of `settings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.settings+0x0): first defined here
libraries/l/webconf.cpp.o:(.bss.settings+0x0): multiple definition of `settings'
sketch/sensor_ap_test.ino.cpp.o:(.bss.settings+0x0): first defined here
collect2: error: ld returned 1 exit status
exit status 1
a.h:
#ifndef LT_MQTT_H
#define LT_MQTT_H
#include "wm_params.h"
#include "settings.h"
#endif //LT_MQTT_H
b.h:
#ifndef LT_SENSORS_H
#define LT_SENSORS_H
#include "wm_params.h"
#include "settings.h"
[...]
#endif // LT_SENSORS_H
wm_params.h:
#ifndef LT_WM_PARAMS_H
#define LT_WM_PARAMS_H
[...]
#endif // LT_WM_PARAMS_H
 
    