开发者

State of static variable in DLL

开发者 https://www.devze.com 2023-01-21 08:28 出处:网络
Scenario: My Application bind a libraryX which has static class. I initialize it in my process. After some time when I load a dll which also use same library X.

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 und开发者_如何学JAVAerstand this behavior / case.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号