a.cpp
const unsigned char whatever[123] = { /* ... */ };
a.h
extern const unsigned char whatever[123];
b.cpp
#include "a.h"
unsigned char x = whatever[0];
// error: undefined reference to 'whatever'
Why do I get an undefined reference error? Without the const
, the error goes away.
How do I share an array of constants among multiple translation units?