I’m attempting to port an Arduino project to use a Photon, but am having issues with variable scoping across multiple included files. I’m compiling using the Particle CLI.
In my main file, I have:
#define READY_STR "READY"
#include "comms.cpp"
In comms.cpp
, I have:
void comms_ready() {
Serial.println(READY_STR);
}
The error produced is:
comms.cpp: In function 'void comms_ready()':
comms.cpp:105:17: error: 'READY_STR' was not declared in this scope
Serial.println(READY_STR);
I’ve tried renaming file extensions to *.cpp
and/or *.ino
, changing where files are included in code, where variables are defined, etc. The only fix seems to be putting the #define READY_STR
at the top of the included file. I’m getting this error for all the global variables used inside of comms.cpp
and other included files, so duplicating all of those global variables is less than ideal. And I definitely don’t want to merge the contents of 10+ files into one!
Any suggestions?