When I compile and link I get:
c:/users/jonathan/appdata/local/arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: C:\Users\jonathan\AppData\Local\Temp\arduino_build_511602\sketch\sp.ino.cpp.o:(.text.setup+0x8): undefined reference to `abc'.
If I remove the keyword Const I get no problems but I would like the variable to be Const.
Any help appreciated.
i tried what you said and got the same issue. I then put the const struct abc definition in the x.h file and changed abc to def in a.cpp, thinking there would now be multiple declarations of abc in a.cpp and sp.cpp, there weren't.
it seemed like const struct Ff abc was more like a #define
not exactly sure if that is what the above says. "static" would limit its scope to the file
Thanks for reply. The link was very useful. It stated:
If we apply the extern qualifier explicitly to the definition of the constant K above, then we give it "external linkage" and it becomes available in other files linked to the file in which its extern definition appears:
So giving the definition extern attribute as well, solved the problem. So in a.cpp, I have the line:
extern const struct Ff abc[] = { {3,4},{4,5} };
The IDE takes your .ino file (and any other .ino files) and combines them together into essentially one .cpp file to compile. Since this is separate from the other 'a.cpp' file, those are separate compilation units and the 'const' keyword makes constants declared in one not visible to the other. That is what is meant by internal linkage
If you already have an extern object defined in an included header, you can't redeclare it in your ino. That is, you can't call "extern const struct Ff abc[];" in your sketch (and you don't need to).