Mental block with multi file code

I have a multi file app with


I am new to this structure in C/C++ so have used declarations in the .h and functions and variables in .cpp files

I have globals vars in app.ino that are used in setup()

const int sizeOfVersion = 7;
const char firmwareVersion[sizeOfVersion] = “ZA011d”;
const char deviceModel[sizeOfVersion] = “fMonPM”;
unsigned char eepSignature = firmwareVersion[5];

I wish to also use these in module1.cpp so I added this

extern unsigned char eepSignature;

to the module1.cpp - and it works okay.

If I then add

extern const char firmwareVersion;

to module1.cpp.

I have a defined struct in the same .cpp

struct { // common struct for attributes stored in EEPROM
char attributeName[sizeOfAttributeName];
char attributeValue[largestAttributeValue];
time_t lastChanged;
} attributes;

and want to do this

sprintf(attributes.attributeValue, “%s”, firmwareVersion); // firmware

I get this error

/firmware/user/…/wiring/inc/spark_wiring_eeprom.h:151:0: undefined reference to “firmwareVersion”

What am I missing here ?

firmwareVersion is defined as const char[] so your extern reference should also be of this or a compatible type (e.g. extern const char* firmwareVersion;).

You are missing the additional notes that are given in the raw error message output that would probably provide more clues about the reason for this error.

Thanks - if i try this change, then the error becomes

undefined reference to “firmwareVersion”

Raw Error at bottom of list

…/…/…/build/target/user/platform-14-mlibuser.a(EEP.o): In function eepromCreateDataTable()': src/EEP.cpp:252: undefined reference tofirmwareVersion’

The line number is the closing brace of the function that contains the reference to ‘firmwareVersion’ (not the line number of the variable usage)

Raw for EEP.cpp (no errors at the end of the block)

new -std=gnu++11 -c -o …/build/target/user/platform-14-msrc/EEP.o src/EEP.cpp

What IDE are you using?
I’d expect some more build output that may help pinpoint the root cause.

If you can share a zip file or with Web IDE a SHARE THIS REVISION link of your project (if you want in a DM) it may be easier to get to the bottom of it.

Thanks I am using the web IDE - havn’t got around to installing the workbench yet.

I’ll DM you.

I haven’t fully got to the bottom of why this plays a role, but when you remove the extern definitions from your EEP.cpp and put this block

extern unsigned char eepSignature;
extern const char firmwareVersion[];
extern const char deviceModel[];

into your EEP.h file the project builds for me.

I really appreciate your time on this - I am still getting an error

/firmware/user/…/wiring/inc/spark_wiring_eeprom.h:151:0: undefined reference to “firmwareVersion”

…/…/…/build/target/user/platform-14-mlibuser.a(EEP.o): In function unsigned char const& EEPROMClass::put<unsigned char>(int, unsigned char const&)': /firmware/user/../wiring/inc/spark_wiring_eeprom.h:151: undefined reference tofirmwareVersion’ collect2: error: ld returned 1 exit status …/…/…/build/ recipe for target ‘target/workspace.elf’ failed make[1]: Leaving directory ‘/firmware/modules/xenon/user-part’ make[1]: *** [target/workspace.elf] Error 1 …/build/ recipe for target ‘modules/xenon/user-part’ failed make: *** [modules/xenon/user-part] Error 2

I’ll DM you a link to the working revision I have

Thanks - working now I put the block into .cpp instead of .h - I’ll soak test tonight and let you know how it goes.