tags:

views:

30

answers:

1

Scenario:

My Application bind a library X which has static class. I initialize it in my process. After some time when I load a dll which also use same library X.

I see content of static variable in dll is not initialized. Where I already initialized it in process before loading DLL.

I added initialization code in DLL main , and its working now.

Question : I need to understand this behavior / case.

+1  A: 

library x is clearly linked as a static library against both the exe, and the dll :- in order to get the behavior you want, library X itself needs to be built as a shared library. So then "my application.exe" and "a.dll" would both use "libraryx.dll" as a result there would only by one instance of the static value.

Chris Becke
Agree, I ran into this once when writing a logging lib in which I had a static logger (singleton).
Ralf