Page MenuHomePhabricator

Problem with access to static constant strings that don't end up defined inside the shared library
Open, HighPublic

Description

It looks like even if a constexpr symbol is defined inside a header, for some reason some compiler will not work.

As it doesn't change much for us (and in retrospect is probably neater), replace the bad usage of

//in header, in AnnClass: public: static constexpr const char* const aString = "some constant stuff that should never change and be referenced by client program";

With a simple static const pointer to char, and put the actual initialization in a compilation unit

//in header, in AnnClass:
public:
    static const char* const aString;
//in implemetation (.cpp) file of AnnClass
const char* const aString = "this string is constant";

This is only valid with classes that are actually exported in the library (most of them are. They are defined with an AnnDllExport macro)


Actually, this is a bad idea and just creating linkage problem on other compiler. As of now, the best idea I have is to stop being too clever about it and just have a static method that return the const string. This gets build into the library and can be retrieved reliably and properly each time.

The "use functions" methods is also the one advised in Microsoft documentations

Event Timeline

Ybalrid created this task.Feb 20 2019, 5:53 AM
Ybalrid claimed this task.Feb 21 2019, 4:16 PM
Ybalrid renamed this task from Problem with access to static constant strings that don't end up defined inside the shared library #180 to Problem with access to static constant strings that don't end up defined inside the shared library.Feb 21 2019, 4:19 PM
Ybalrid triaged this task as High priority.
Ybalrid changed the visibility from "All Users" to "Public (No Login Required)".