Static objects in libraries

Hi!

I have the following problem with C++ programs on Unix:

There is a binary executable program called, e.g. Main. It is dynamically linked with two shared libraries: Shared1 and Shared2. Both of these libraries, in turn, are statically linked with a static library called Static. This static library has a static object called StaticObj declared and defined as:

class MyClass
{
    public:
        static MyClass StaticObj;
};

MyClass MyClass::StaticObj;

Now, when I run the execucable Main, I get into the problem that StaticObj is initialized twice. This means that MyClass constructor is called twice on the same address. The same story happens with the destructors.

It is naturally that such behaviour would not be desired, especially when you deal with some objects that have states. Neither is applicable variant, which makes two independed copies of StaticObj for libraries Shared1 and Shared2 (imagine that StaticObj is a mutex!).

Has anyone run across a similar problem and found a good solution?

Thanks!