I have spent the better part of today trying to figure out why I can't get this to work...
I have this project where, because of previous design considerations, have implemented a singleton class that initializes a bunch of separate sensors in this system that I am running.
The system was originally built for the Particle Boron, but now I am trying to make it work with the Adafruit Feather M0, so I have had to refactor several things and omit lots of lines of Particle RTOS specific things.
However, in doing this, I find that my singleton class no longer works.
Sensors.h:
.
.
.
class Sensors{
static Sensors *instance;
public:
static Sensors *getInstance() {
if (!instance) {
instance = new Sensors;
}
return instance;
}
}
private:
Sensors();
.
.
.
Sensors.cpp:
.
.
.
Sensors::Sensors() : dht22(DHTPIN, DHTTYPE) {
#ifdef PLATFORM_ID
sensorLog("app.Sensors");
#endif
}
.
.
.
main.ino:
.
.
.
// Sensors
Sensors Sensors::instance = nullptr;
Sensors allSensors = allSensors->getInstance();
void setup(){
.
.
.
As I try to compile this with ArduinoISP, no matter what I try, I get the following error:
sketch/main.ino.cpp.o: in function `Sensors::getInstance()':
sketch/lib/Sensors/src/Sensors.h:23: undefined reference to `Sensors::Sensors()'
collect2: error: ld returned 1 exit status
exit status 1
[Error] Exit with code=1
I have tried things like changing the line
instance = new Sensor;
to
instance = new Sensor();
making the instance public, changing the Sensor constructor, but all of this to no avail. Could this be a compiler issue? Why would this work on a Particle board, but not an Adafruit Feather M0?