I want to provide a string constant in an API like so:
extern const char* const SOME_CONSTANT;
But if I define it in my static library source file as
const char* const SOME_CONSTANT = "test";
I'm getting linker errors when linking against that library and using SOME_CONSTANT:
Error 1 error LNK2001: unresolved external symbol "char const * const SOME_CONSTANT" (?SOME_CONSTANT@@3QBDB)
Removing the pointer const-ness (second const keyword) from both the extern const char* const
declaration and the definition makes it work. How can I export it with pointer const-ness?
const std::string
in the first place? – Florineflorioextern
declaration visible in the source file defining the constant? – Florineflorioconst char *
is the C "string" type and it's perfectly valid to use it in C++. – Ensileoperator+
, copoying and template argument deduction come to mind. – Florineflorio