I create only C ++ - a library for templates only. However, I would also like to provide an “empty” shared library, so that by controlling SONAME I can force the rebuilds of template consumers whenever templates change so that the ABI template is incompatible.
Unfortunately, if a particular user has -Wl,--as-needed in his LDFLAGS , the linker is about to remove my shared library from NEEDED because the compiled executable does not request any characters from it. How can I guarantee that the program will always be associated with my library, it is advisable not to introduce unnecessary fake function calls (or, if necessary, which makes them the least burdensome)?
Edit: As a note, a particular class of templates provides static methods, and usually only those static methods are used. Thus, you should not rely on anything placed in the constructor, and I really would like to avoid burdening all methods with some kind of coercion.
Inspired by @EmployedRussian, I achieved:
extern int dummy; namespace { struct G { inline G() { dummy = 0; } }; static const G g; }
But, unfortunately, this performs the assignment once for each unit, including the header file.
Michał Górny
source share