我对共享库有以下问题
创建共享库
class A
{
static int callCount;
A() { callCount++; }
}
int A:callCount = 0;
class Main
{
Main()
{
A a1();
A a2();
}
}
现在创建一个进程加载这个共享库更多次,我希望 callCount 只属于共享库而不属于整个进程
dlopen("shared.so", RTLD_LAZY);
// after some code i can construct Main()
// and now i will open the shared object again
dlopen("shared.so", RTLD_LAZY);
// now if i construct Main from the new library i want to have a new
// initialized callCount eq 0 but its 2
我怎么解决这个问题