C++ extern const link error

In C++, I tried to reference a constant in flash defined in another file using this declaration:

extern const int count;

In another C++ file I had the definition:

const int count = 1;

(The original test case had more to it, but I boiled it down to this simple scenario.)

The linker gives the error "undefined reference to 'count'".  I am using ARM GCC 9.3.1 on a Cortex-M0+ MCU.

I found if I took off the "const" in both places, thus moving it from flash to RAM, there was no problem.  I also eventually figured out that it all linked (and lived in flash) if I added 'extern "C"' to both.  This is an adequate work-around, but I'd like to know what the problem is.  Is it a bug?  Is there something missing from my declarations?

Parents Reply Children
No data
More questions in this forum