There is a c ++ linux project consisting of a shell that loads various modules made in the form of shared libraries (in fact, they are plugins loaded via QPluginLoader, but essentially the same shared libraries). Modules, in turn, use each other's methods. Compiler clang 6, gold linker.
Found a strange problem with static variables. For example, we have three libraries L1, L2, L3. L1 and L2 use L3. A static variable is defined in one of the exported L3 classes:
test.h: class AAA { public: static QHash<int,int> data; }; test.cpp: QHash<int,int> AAA::data = {{1,2} , {2,3}}; If the project is linked without an option
-Wl, - as-needed
then when you close the application, the memory allocated for AAA :: data is deleted twice, and crash occurs naturally. It seems that the L1 and L2 libraries, when linked to L3, generate a memory free code twice. After activating -Wl, -as-needed, the crashes disappear. Is this generally normal behavior?
QPluginLoaderor something similar up there, then it is probably incorrectly used ... - Fat-Zer