At the moment I have a configuration file called "config.h". This file has multiple parameters that are retrieved by multiple header files.
Folder source structure under PlatformIO:
src/
├── main.cpp
├── Temperature.h
├── Temperature.cpp
├── config.h
main.cpp requests a configuration integer from the config.h file. temperature.h has the config.h included to get the address of a temperature sensor.
Now I get the error in the linker:
.pio\build\esp32dev\src\main.cpp.o:(.data.mode+0x0): multiple definition of `mode'
.pio\build\esp32dev\src\Temperature.cpp.o:(.data.mode+0x0): first defined here
.pio\build\esp32dev\src\main.cpp.o:(.bss.address+0x0): multiple definition of `address'
.pio\build\esp32dev\src\Temperature.cpp.o:(.bss.address+0x0): first defined here
I've tried setting Pragma once and header guards in the config.h but it didn't get any results.
config.h:
#ifndef CONFIG_H
#define CONFIG_H
#pragma once
/* WiFi Settings */
#define WIFI_SSID "WiFiOnBusiness"
#define WIFI_PASSWORD "WiFiPassword"
/* Temperature BME280 Configuration (Keep as it) */
uint8_t address = 0;
uint8_t mode = 3;
#endif
What is the correct way to make sure to import the config file into multiple header files?