Linux C++ static/anonymous data in DLL


#1

I have spent the last day grappling with some very weird behavior in NativePtr.cpp
when loaded as a Linux libhail.so. A static data object (used to hold JNI
jfieldID values for fast access to fields of the NativeBase object) appears to
give two copies at different addresses, apparently with different functions in the same file seeing different instances. That caused huge confusion when I was
trying to initialize the data only once …

For the moment I’m rolling with the punches and doing all initialization in the
constructor, so that the initialization happens once for each object. But if this behavior crops up elsewhere for some reason, anything could happen.